Pull Data From One Column Based On Condition From a Different Column
Hey guys!
I've been at this for a while, Magic ETL, Analyzer, Google, nothing seems to answer the following (maybe it's because I'm new)
I can't seem to find a means to pull data from a numerical column based on the condition of a categorical column without aggregating as a sum. Could anyone help me with this without changing the values from the numerical column?
My table is like the following:
Column A | Column B | Date |
234 | 2019 | 2019-06-13 |
0 | 2019 | 2019-09-30 |
16 | 2019 | 2019-12-21 |
1 | 2020 | 2020-06-13 |
1 | 2020 | 2020-09-30 |
32 | 2020 | 2019-12-21 |
And I want to turn it into the following:
Previous | Current | Date |
234 | n/a | 2019-06-13 |
0 | n/a | 2019-09-30 |
16 | n/a | 2019-12-21 |
n/a | 1 | 2020-06-13 |
n/a | 1 | 2020-09-30 |
n/a | 32 | 2019-12-21 |
I'm trying to use the advanced comparative gauge tool in the Analyzer.
Any tips or ideas, I am all ears *ahem* ...eyes
Best Answer
-
I’m on mobile and the dojo won’t let me edit my reply but the formula should look like this for prior
CASE WHEN `Column B` = YEAR(CURRENT_DATE) - 1 THEN `Column A` END
and this for current
CASE WHEN `Column B` = YEAR(CURRENT_DATE) THEN `Column A` END
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1
Answers
-
Hi @user052846
CASE statements are your friend in this case. Assuming you’re looking for data from the prior year you can use logic to conditionally set a new column value using a case statement in a beast mode.
For your current Column:
CASE WHEN `Column B` YEAR(CURRENT_DATE) THEN `Column A` END
Previous Column
CASE WHEN `Column B` YEAR(CURRENT_DATE) - 1 THEN `Column A` END
since no ELSE condition is specified in the case statement it defaults to NULL (blank)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1 -
I’m on mobile and the dojo won’t let me edit my reply but the formula should look like this for prior
CASE WHEN `Column B` = YEAR(CURRENT_DATE) - 1 THEN `Column A` END
and this for current
CASE WHEN `Column B` = YEAR(CURRENT_DATE) THEN `Column A` END
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 296 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 677 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 45 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive