Nested Case and Concat Statement
Hi,
I am trying to figure out how to create an Etl that expresses: If a particular year has a result then concat that with another column's result. Something like:
CONCAT(case WHEN 2015
= 1 then '2015', '-', Virtual vs In-Person
else '' end)
2015 has a 1/0 constant and I want the result to be if they attended in person (so if 2015 = 1 then the result is 2015-Virtual or 2015-In-Person depending on what is in the Virtual vs In-Person Column)
Thanks in advance!
Best Answer
-
Something like this should work for you:
CASE WHEN `2015`=1 THEN CONCAT('2015-', `Virtual vs In-Person`) ELSE '' END
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1
Answers
-
Something like this should work for you:
CASE WHEN `2015`=1 THEN CONCAT('2015-', `Virtual vs In-Person`) ELSE '' END
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
Thank you so much! I don't know why I thought I needed the Concat to envelop the whole thing. :)
0 -
Another question @grantsmith. How do I nest it with multiple years? I tried using:
CASE WHEN `2015`=1 THEN CONCAT('2015-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2016`=1 THEN CONCAT('2016-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2017`=1 THEN CONCAT('2017-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2018`=1 THEN CONCAT('2018-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2019`=1 THEN CONCAT('2019-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2020`=1 THEN CONCAT('2020-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2021`=1 THEN CONCAT('2021-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2022`=1 THEN CONCAT('2022-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2023`=1 THEN CONCAT('2023-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2024`=1 THEN CONCAT('2024-'
`Virtual vs In-Person`) ELSE '' END
CASE WHEN `2025`=1 THEN CONCAT('2025-'
`Virtual vs In-Person`) ELSE '' END
But I keep getting an unknown error message in the ETL.
0 -
you only need the first CASE statement all the others should just be WHEN and only a single else at the end and one END at the very end
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
Alternatively I’d look into unpivoting your data so it’s structured with a year column and the actual year value for each row then you don’t need the massive case statement to update every year and it’d be a simple CONCAT function with the year column and your virtual in person column
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
I got this error when I tried it like this. I don't think I can use unpivot. I had to pivot and add the constant that I needed to get to this point.
Thanks for your help!!!
0 -
You have a comma at the end of the first line, you don't separate WHEN statements with commas, this is most likely why you're getting the error with your syntax. I do agree with @GrantSmith that this could be a good use case for unpivoting, specially if a single Row might have a value of
1
for more than a single year, as the beast mode will only return a value for the first year that matches.0 -
Thank you so much!!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive