Do a "Sumif" using CASE that's independent of other CASEs
How do I create a beast mode calculation to "sumif" without letting other CASE affecting?
Apologies for the vague description, I'm unsure on how to word this. This is my example dataset
Business | Dept | Metrics | Values |
Clothing | Kids | Cost | 21 |
Clothing | Kids | Sales | 80 |
Clothing | Women | Cost | 35 |
Clothing | Women | Sales | 50 |
Food | Cooked | Cost | 65 |
Food | Cooked | Sales | 62 |
Food | Fresh | Cost | 15 |
Food | Fresh | Sales | 60 |
I want to create a table card that looks like this, where MyCol is a calculated column populated by the sum of Cost when Metrics = Sales
Metrics | sum of Values | MyCol |
Cost | 136 | 0 |
Sales | 252 | 136 |
Using
(CASE when `Metrics`='Sales' then SUM(case when `Metrics`='Cost' then `Values` else 0 end) else 0 end)
doesn't work because by the time the sum calculation is done, all Cost rows have already been eliminated by the first CASE.
Could anyone help with this?
Comments
-
So to do what you're looking for, you'll need to alter your source data a bit. You can do this in a data transform, but basically you'll need to seperate out your Metrics into a Cost column and Sales column and then just have the corresponding values below. So you would have the following:
Business Dept Cost Sales Clothing Kids 21 80 Clothing Women 35 50 Food Cooked 65 62 Food Fresh 15 60 If you're doing this in a MySQL transform, you can use the following:
SELECT `Business`, `Dept`, SUM(CASE WHEN `Metrics` = 'Cost' THEN `Values` END) AS 'Cost',
SUM(CASE WHEN `Metrics` = 'Sales' THEN `Values` END) AS 'Sales'
FROM SourceTable
GROUP BY `Business, `Dept`
This way you break your Cost and Sales into seperate columns and can then show them together.
Hopefully this will get you on the right track. Let me know if you have questions from this point.
Sincerely,ValiantSpur
**Please mark "Accept as Solution" if this post solves your problem
**Say "Thanks" by clicking the "heart" in the post that helped you.1 -
Thanks, this one pointed me in the right direction. I was able to do what I want by repeating some numbers in transform. I think I'm very close to what I had intended and that wouldn't be possible without your help!
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 101 SQL DataFlows
- 622 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 747 Beast Mode
- 59 App Studio
- 41 Variables
- 686 Automate
- 176 Apps
- 453 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 395 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 6 Software Integrations
- 125 Manage
- 122 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