Case Syntax
I am having difficulty understanding the case syntax while using magic ETL.
In the current Example, I have a list of properties and coded them to display a text column of the region for each specific property. Unfortunately, there is no address line to be able to parse and use to make the regions so I'm hard-coding the numbers.
Case when `lookup_code`= 1026 THEN "Charlotte"
ELSE WHEN `lookup_code`= 1024 THEN "Charlotte"
ELSE WHEN `lookup_code`=1020 or `lookup_code`= 1009 or `lookup_code`=1023 THEN "Raleigh/Durham"
ELSE WHEN `lookup_code`=1019 or `lookup_code`= 1010 or `lookup_code`= 1016 or `lookup_code`=3001 THEN "Dallas"
ELSE WHEN `lookup_code`=1014 or `lookup_code`=1022 or `lookup_code`=1006 or `lookup_code`=1013 THEN "Austin"
ELSE WHEN `lookup_code`=1025 or `lookup_code`=1017 or `lookup_code`=1005 THEN "Orlando"
ELSE WHEN `lookup_code`=1021 or `lookup_code`=1018 or `lookup_code`=1015 or `lookup_code`=1011 THEN "Tampa"
ELSE WHEN `lookup_code`=1030 THEN "Miami"
ELSE "New Property Please Update"
END
Or is this a alternative why to set it up
Case when `lookup_code`= 1026 THEN "Charlotte"
CASE `lookup_code`= 1024 THEN "Charlotte"
CASE `lookup_code`=1020 or `lookup_code`= 1009 or `lookup_code`=1023 THEN "Raleigh/Durham"
CASE `lookup_code`=1019 or `lookup_code`= 1010 or `lookup_code`= 1016 or `lookup_code`=3001 THEN "Dallas"
CASE `lookup_code`=1014 or `lookup_code`=1022 or `lookup_code`=1006 or `lookup_code`=1013 THEN "Austin"
CASE `lookup_code`=1025 or `lookup_code`=1017 or `lookup_code`=1005 THEN "Orlando"
CASE `lookup_code`=1021 or `lookup_code`=1018 or `lookup_code`=1015 or `lookup_code`=1011 THEN "Tampa"
CASE `lookup_code`=1030 THEN "Miami"
ELSE THEN "New Property Please Update"
END
I could use SQL to split them up but it seems redundant to split them and then join the data sets.
Best Answer
-
Instead of using ELSE WHEN just use WHEN for additional cases. Use just ELSE for your default clause.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2
Answers
-
Instead of using ELSE WHEN just use WHEN for additional cases. Use just ELSE for your default clause.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**2 -
thanks its always the simpler dropped text that I have problems with.
0 -
@mhouk to further simplify your case statement, you can use the IN clause so that you have just one line per city. Something like this:
Case WHEN `lookup_code` IN (1024,1026) THEN 'Charlotte' WHEN `lookup_code` IN (1009,1020,1023) THEN 'Raleigh/Durham' WHEN `lookup_code` IN (1010,1016,1019,3001) THEN 'Dallas' WHEN `lookup_code` IN (1006,1013,1014,1022) THEN 'Austin' WHEN `lookup_code` IN (1005,1017,1025) THEN 'Orlando' WHEN `lookup_code` IN (1011,1015,1018,1021) THEN 'Tampa' WHEN `lookup_code` = 1030 THEN 'Miami' ELSE 'New Property Please Update' END
You can use the IN statement one line and equals on another line as shown above since you only had one entry for Miami. The end result is a much more concise case statement.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
thanks for your input! I didn't think you could use an array of numbers for the In function I thought you had to use another column.
0 -
I did a quick test before posting and it worked. It's assuming your lookup_code column is numeric. If it is a string column, you would need to put single quotes around each value like this: ('1000','1001')
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
Alternatively you could store three values in a lookup table dataset and use an Etl to left join it to your original data. Then use a formula tile to do a coalesce to set the default value (your else clause) so you keep your lookup list in a single place rather than possibly across multiple beast modes.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**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