Nested case function (average over time period)
Hello,
I am trying to build a card that has dynamic goals incorporated into it based on the 30 day history.
The below is what I currently have set up as the goals based on the mdse_grp_ref_i which allow it to roll up to higher level goals based on the mix of items that fall into each grp.
(case
when `mdse_grp_ref_i` = '1' then 8.46
when `mdse_grp_ref_i` = '13' then 7.41
when `mdse_grp_ref_i` = '10' then 9.27
when `mdse_grp_ref_i` = '3' then 10.20
when `mdse_grp_ref_i` = '4' then 11.35
else 0
end)
What I would like to get to is a state where I can plug in a formula (already created in a separate Beast Mode Calc) after each "then" in the above statement and also have this formula take an average of the previous 30 days. I am not sure if this is possible. I wrote the below code as a rough attempt, but am having trouble getting it to work. For starters I know DOMO isn't a fan of having sum or avg functions within the case statement but am not sure how to pull it out and still have the calculation work. At the same time I am unsure of how to have the portion of the code below, which calculates the percentage of item/locations that started with less inventory that they should, average over the past 30 days.
(case
when `mdse_grp_ref_i` = '1' then (0.6527 * (avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end))+0.0189)
when `mdse_grp_ref_i` = '13' then (0.6527 * (avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end))+0.0189)
when `mdse_grp_ref_i` = '10' then (0.6527 * (avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end))+0.0189)
when `mdse_grp_ref_i` = '3' then (0.6527 * (avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end))+0.0189)
when `mdse_grp_ref_i` = '4' then (0.6527 * (avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end))+0.0189)
else 0
end)
Any help you can provide will be much appreciated.
Thanks,
Adam
Comments
-
Hey Adam @user02674,
From the looks of the nested beast mode, as you assessed, it doesn't like you putting aggregate functions into what it's seeing as a row level function. This is probably why the code isn't functional.
Have you considered using ETL or Dataflow to hard code the values in these segments into their own column? (0.6527 * (avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end))+0.0189)
That way your dataset has the column value to multiply by already in the data, so at that point it's just a matter of simple one part case statements.
Hope this is helpful.
**Say 'Thanks' by clicking the thumbs up in the post that helped you.
**Please mark the post that solves your problem as 'Accepted Solution'0 -
try adding max after avg function
(0.6527 * (max(avg(case when `loc_type` = 'STR' and (`boh_8am` + `str_ow_8am_q`) < `int_new1` then 1 else 0 end) * 100 / sum(case when `loc_type` = 'STR' then 1 else 0 end)))+0.0189)
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive