Using SUM and MAX
I am trying to get a quarterly view of a value where Q1 and Q2 are full quarters and Q3 is a year-to-date calculation. So my table is showing Quarters as rows. But when I try to pull the data using a beast mode like below, I get errors because I'm using the SUM aggregation with the MAX for the date (or the number of days). Is there a way to do this where I can apply the MAX portion of this to only Q3 and thus not have the aggregation conflict?
sum(case when `ATTRIBUTE A` = 'Condition A' and `ATTRIBUTE B` = 'Condition B' then
case when `QUARTER` = 'Q1' then `Value`
when `QUARTER` = 'Q2' then `Value`
when `QUARTER` = 'Q3' then ((`Value`/90) * max(datediff(case when `ATTRIBUTE A` = 'Condition A' then `DATE` end,'2018-01-01')))
END
END )
Best Answer
-
Thank you for the response. I wasn't able to insert a new attribute into our data table since I didn't have the time to do so. Our table is a large Hadoop table.
But I did find another solution. By taking the 'MAX' out of the conditional statement with the 'SUM' and then multiplying it when the `QUARTER` = 'Q3'. I also needed to put the 'MAX' before the conditional rather than within it. Like this:
(sum(case when `ATTRIBUTE A` = 'Condition A' and `ATTRIBUTE B` = 'Condition B' then
case when `QUARTER` = 'Q1' then `Value`
when `QUARTER` = 'Q2' then `Value`
when `QUARTER` = 'Q3' then (`Value`/90)
END
END )* max(case when `QUARTER` = 'Q3'
then datediff(case when `ATTRIBUTE A` = 'Condition A' then `DATE` end,'2018-01-01')
END))
This worked perfectly for me.
Thanks for your response.
0
Answers
-
For a similar calculation, I ended up adding a new row to my dataset and had it calculate the MAX applicable date for the range.
That way you can use the "MAX Date" almost as it's own variable in your beastMode. So if you added a `MaxDate` column to your data your new BeastMode would look like this:
sum(case when `ATTRIBUTE A` = 'Condition A' and `ATTRIBUTE B` = 'Condition B' then
case when `QUARTER` = 'Q1' then `Value`
when `QUARTER` = 'Q2' then `Value`
when `QUARTER` = 'Q3' then ((`Value`/90) * (datediff(`MaxDate`,'2018-01-01')))
END
END )Let me know if you need any assitance in builiding the new column and I'll be glad to give more detail.
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.0 -
Thank you for the response. I wasn't able to insert a new attribute into our data table since I didn't have the time to do so. Our table is a large Hadoop table.
But I did find another solution. By taking the 'MAX' out of the conditional statement with the 'SUM' and then multiplying it when the `QUARTER` = 'Q3'. I also needed to put the 'MAX' before the conditional rather than within it. Like this:
(sum(case when `ATTRIBUTE A` = 'Condition A' and `ATTRIBUTE B` = 'Condition B' then
case when `QUARTER` = 'Q1' then `Value`
when `QUARTER` = 'Q2' then `Value`
when `QUARTER` = 'Q3' then (`Value`/90)
END
END )* max(case when `QUARTER` = 'Q3'
then datediff(case when `ATTRIBUTE A` = 'Condition A' then `DATE` end,'2018-01-01')
END))
This worked perfectly for me.
Thanks for your response.
0 -
...or sorry, also needed to add the 'ELSE 1' at the end of the last statement so that the 'Q1' and 'Q2' values would be multiplied by 1.
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