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.9K Product Ideas
- 1.9K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 303 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 104 SQL DataFlows
- 640 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 768 Beast Mode
- 70 App Studio
- 43 Variables
- 717 Automate
- 185 Apps
- 462 APIs & Domo Developer
- 56 Workflows
- 14 DomoAI
- 39 Predict
- 16 Jupyter Workspaces
- 23 R & Python Tiles
- 402 Distribute
- 116 Domo Everywhere
- 277 Scheduled Reports
- 9 Software Integrations
- 134 Manage
- 131 Governance & Security
- 8 Domo Community Gallery
- 44 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 111 Community Announcements
- 4.8K Archive