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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 603 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 697 Beast Mode
- 43 App Studio
- 39 Variables
- 658 Automate
- 170 Apps
- 441 APIs & Domo Developer
- 42 Workflows
- 5 DomoAI
- 32 Predict
- 12 Jupyter Workspaces
- 20 R & Python Tiles
- 386 Distribute
- 111 Domo Everywhere
- 269 Scheduled Reports
- 6 Software Integrations
- 113 Manage
- 110 Governance & Security
- 8 Domo University
- 30 Product Releases
- Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive