SUM of CASE in Beast Mode
Hi,
I am trying to sum a column based on date value output from another case statement, but i dont see anything getting calculated when i check the formula.
there are no formula validation issues.
SUM((CASE when (CASE when DATE_FORMAT(`Date`,'%d')=1
then
(CASE when DATE_FORMAT(`Date`,'%m')=1
then 'Open Month' else
(CASE when DATE_FORMAT(`Date`,'%m')=4
then 'Open Month' else
(CASE when DATE_FORMAT(`Date`,'%m')=7
then 'Open Month' else
(CASE when DATE_FORMAT(`Date`,'%m')=10
then 'Open Month' else '' end)
end)
end)
end)
else
(CASE when LAST_DAY(`Date`)=`Date`
then
(CASE when DATE_FORMAT(`Date`,'%m')=6
then 'Close Month' else
(CASE when DATE_FORMAT(`Date`,'%m')=9
then 'Close Month' else
(CASE when DATE_FORMAT(`Date`,'%m')=12
then 'Close Month' else '' end)
end)
end)
else
(CASE when CURRENT_DATE()=`Date`
then 'Close Month' else '' end)
end)
end)='Open Month' then `Total_HC_Opening` end))
Best Answers
-
You're just trying to sum up Total_HC_Opening for the first day of certain months?
I think you could really simplify this:
SUM(CASE WHEN DATE_FORMAT(`Date`,'%d') = 1 AND DATE_FORMAT(`Date`,'%m') IN (1,4,7,10) THEN `Total_HC_Opening` END)
Does this work?
Aaron
MajorDomo @ Merit Medical
**Say "Thanks" by clicking the heart in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
When using DATE_FORMAT, the result is not a value, but a string. You need to use single quotes and they need to be two characters long. Something like this:
sum(case when DATE_FORMAT(`Date of Invoice`,'%d')='01' and DATE_FORMAT(`Date of Invoice`,'%m')='02' then `Sales at constant Exchange Rate` end)
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
I had the same thought as @ST_-Superman-_ but it actually works for me as-is.
SUM(CASE WHEN DATE_FORMAT(`Date`,'%d') = 1 AND DATE_FORMAT(`Date`,'%m') IN (1,4,7,10) THEN `Value1` END)
See attached table sum file.
Also from this site the other attachment with format explanation.
Aaron
MajorDomo @ Merit Medical
**Say "Thanks" by clicking the heart in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"1
Answers
-
You're just trying to sum up Total_HC_Opening for the first day of certain months?
I think you could really simplify this:
SUM(CASE WHEN DATE_FORMAT(`Date`,'%d') = 1 AND DATE_FORMAT(`Date`,'%m') IN (1,4,7,10) THEN `Total_HC_Opening` END)
Does this work?
Aaron
MajorDomo @ Merit Medical
**Say "Thanks" by clicking the heart in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"0 -
Yes, I am trying the same as you are suggesting but still returns nothing.
0 -
When i use only month from date format it is showing the calculation but when i add date as 1 it shows nothing, infact i tried with all possible date but comes up nothing.
0 -
When using DATE_FORMAT, the result is not a value, but a string. You need to use single quotes and they need to be two characters long. Something like this:
sum(case when DATE_FORMAT(`Date of Invoice`,'%d')='01' and DATE_FORMAT(`Date of Invoice`,'%m')='02' then `Sales at constant Exchange Rate` end)
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman0 -
I had the same thought as @ST_-Superman-_ but it actually works for me as-is.
SUM(CASE WHEN DATE_FORMAT(`Date`,'%d') = 1 AND DATE_FORMAT(`Date`,'%m') IN (1,4,7,10) THEN `Value1` END)
See attached table sum file.
Also from this site the other attachment with format explanation.
Aaron
MajorDomo @ Merit Medical
**Say "Thanks" by clicking the heart in the post that helped you.
**Please mark the post that solves your problem by clicking on "Accept as Solution"1
Categories
- All Categories
- 1.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 292 Workbench
- 4 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 95 SQL DataFlows
- 600 Datasets
- 2.1K Magic ETL
- 3.7K Visualize
- 2.4K Charting
- 685 Beast Mode
- 43 App Studio
- 38 Variables
- 655 Automate
- 170 Apps
- 438 APIs & Domo Developer
- 42 Workflows
- 5 DomoAI
- 32 Predict
- 12 Jupyter Workspaces
- 20 R & Python Tiles
- 383 Distribute
- 110 Domo Everywhere
- 267 Scheduled Reports
- 6 Software Integrations
- 111 Manage
- 108 Governance & Security
- 8 Domo University
- 25 Product Releases
- Community Forums
- 39 Getting Started
- 29 Community Member Introductions
- 98 Community Announcements
- Domo Community Gallery
- 4.8K Archive