An issue has occurred during processing. We are unable to complete the request at this time.
Hi I am new to Domo and have no SQL knowledge. I am trying to get our YTD cases quantity with some condition taken from other working beast mode. If someone can please help me figure the beast mode below why it's erroring. Thank you ion advance.
SUM(CASE WHEN `Year`=2020 AND `Month #` <=`Month # for Today`
THEN (SUM(CASE
WHEN `Unit price`>100 THEN ((`SO Ordered Qty`)*`Cases per Pallet`)
ELSE (`SO Ordered Qty`)
END))
ELSE 0
END)
Best Answers
-
I would get rid of your outer SUM function as I think it not necessary since you are already summing inside your case statement. I would suggest this:
CASE WHEN `Year`=2020 AND `Month #` <=`Month # for Today` THEN (SUM (CASE WHEN `Unit price`>100 THEN (`SO Ordered Qty`*`Cases per Pallet`) ELSE `SO Ordered Qty` END) ) ELSE 0 END
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
HI @user033690
For your specific beast mode it's failing because you're attempting to aggregate on top of an aggregate which isn't possible. When starting a problem like this it's good practice to start breaking these out into smaller chunks to validate the data as you're working through it.
First thing you'll want to do is instead of hard coding 2020 in your beast mode you're wanting the current year. As is it will break when January 2021 comes around and you'd need to keep updating this beast mode every year.
So instead of 2020 you can get the year of the current date:
YEAR(CURRENT_DATE())
Depending on how you're wanting to display this information depends on how to solve your problem. If you're just getting a text card with a single value or using at a summary number this should work:
Essentially this is combining your filter conditions into a single CASE statement instead of trying to do sum of sum twice.
If you're wanting a running YTD total then you'll need to utilize a Window Function (this requires a feature switch turned on. Talk to your CSM if you don't have it enabled yet).
SUM(SUM(CASE WHEN `Unit price`>100 THEN (`SO Ordered Qty`)*`Cases per Pallet` ELSE (`SO Ordered Qty`) END )) OVER (PARTITION BY `Year`)
(these are all untested code examples but should work)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**3
Answers
-
I would get rid of your outer SUM function as I think it not necessary since you are already summing inside your case statement. I would suggest this:
CASE WHEN `Year`=2020 AND `Month #` <=`Month # for Today` THEN (SUM (CASE WHEN `Unit price`>100 THEN (`SO Ordered Qty`*`Cases per Pallet`) ELSE `SO Ordered Qty` END) ) ELSE 0 END
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
HI @user033690
For your specific beast mode it's failing because you're attempting to aggregate on top of an aggregate which isn't possible. When starting a problem like this it's good practice to start breaking these out into smaller chunks to validate the data as you're working through it.
First thing you'll want to do is instead of hard coding 2020 in your beast mode you're wanting the current year. As is it will break when January 2021 comes around and you'd need to keep updating this beast mode every year.
So instead of 2020 you can get the year of the current date:
YEAR(CURRENT_DATE())
Depending on how you're wanting to display this information depends on how to solve your problem. If you're just getting a text card with a single value or using at a summary number this should work:
Essentially this is combining your filter conditions into a single CASE statement instead of trying to do sum of sum twice.
If you're wanting a running YTD total then you'll need to utilize a Window Function (this requires a feature switch turned on. Talk to your CSM if you don't have it enabled yet).
SUM(SUM(CASE WHEN `Unit price`>100 THEN (`SO Ordered Qty`)*`Cases per Pallet` ELSE (`SO Ordered Qty`) END )) OVER (PARTITION BY `Year`)
(these are all untested code examples but should work)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**3
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