Beast Mode for Summary on Card Needed
I am not strong with case statements (working on it). How do I build a beast mode for the Summary Section of a card that will display the date range and total dollars. Below is a beast mode we created for our report (card) to display results, I just cant get the date range and figures to show in the Summary.
CASE WHEN
DAY(CURDATE()) >= 1 AND DAY(CURDATE()) <= 18 THEN
Sum(case when YEAR(`Date`) = YEAR(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) and DATE_FORMAT(`DATE`,'%m') = MONTH(DATE_SUB(CURDATE(),INTERVAL 1 MONTH))
then `Total Retail Change $` End)
else
Sum(case when YEAR(`Date`) = YEAR(CURDATE()) and DATE_FORMAT(`DATE`,'%m') = MONTH(CURDATE())
then `Total Retail Change $` End)
end
Any help is greatly appreciated.
Comments
-
Hi @user11590
I dint understand the statement and the condition provided by you in below case.
I could see `Total Retail Change $` is same in both the condition.
please repharase is cleary, so that I can try to help you on this.
Below case for you refrence:
SUM(CASE WHEN `transaction_type` = 'Actuals' AND
(
( YEAR(`transaction_date`) = YEAR(CURRENT_DATE()) AND MONTH(`transaction_date`) < 7 ) OR
( YEAR(`transaction_date`) = YEAR(CURRENT_DATE())-1 AND MONTH(`transaction_date`) >= 7 )
)
THEN
`net`
ELSE 0
END)Thanks,
Neeti
Please do like if you are happy with my reply.
0 -
@user11590 - You could utilize CONCAT to combine the different data elements.
Note: The following code is untested.
I'm utilizing your same logic for the dates to only display the dates where it's matching the logic of the revenue $
CONCAT(
MIN(
CASE WHEN DAY(CURDATE()) >= 1 AND DAY(CURDATE()) <= 18 THEN
CASE WHEN YEAR(`Date`) = YEAR(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) and DATE_FORMAT(`DATE`,'%m') = MONTH(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) then
`DATE`
END
ELSE
Sum(case when YEAR(`Date`) = YEAR(CURDATE()) and DATE_FORMAT(`DATE`,'%m') = MONTH(CURDATE())
THEN
`DATE`
END)
end
),
'-'
,MAX(
CASE WHEN DAY(CURDATE()) >= 1 AND DAY(CURDATE()) <= 18 THEN
CASE WHEN YEAR(`Date`) = YEAR(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) and DATE_FORMAT(`DATE`,'%m') = MONTH(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) then
`DATE`
END
ELSE
Sum(case when YEAR(`Date`) = YEAR(CURDATE()) and DATE_FORMAT(`DATE`,'%m') = MONTH(CURDATE())
THEN
`DATE`
END)
end
),
, ' '
SUM(
CASE WHEN DAY(CURDATE()) >= 1 AND DAY(CURDATE()) <= 18 THEN
CASE WHEN YEAR(`Date`) = YEAR(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) and DATE_FORMAT(`DATE`,'%m') = MONTH(DATE_SUB(CURDATE(),INTERVAL 1 MONTH)) then
`Total Retail Change $`
END
ELSE
Sum(case when YEAR(`Date`) = YEAR(CURDATE()) and DATE_FORMAT(`DATE`,'%m') = MONTH(CURDATE())
THEN
`Total Retail Change $`
END)
end
)
)The downside to this is that your sum $ amount won't be formatted as a nice currency anymore. There are additional case statements that you can utilize to format it properly but make for very ugly code currently until Domo decides to allow SQL formatting functions in their beast modes.
What I would recommend is creating three separate Beast Modes to make testing easier. One for the first date, one for the last date and one for the total amount. Once those have been written and verified they're correct you can create the fourth summary beast mode and just do:
CONCAT(
[INSERT MIN DATE BEASTMODE HERE]
,' - '
, [INSERT MAX DATE BEASTMODE HERE]
, ' '
, [INSERT $ BEAST MODE HERE]
)When you insert it it will expand the code into your summary number beast mode that was already written and tested.
An example Beast Mode to display $ amounts in an abbreviated form (handles correclty up to numbers < $1T)
CONCAT('$',CASE WHEN LENGTH(ROUND(SUM(`Total`), 0)) >= 10 THEN
CONCAT(
ROUND(SUM(`Total`) / 1000000000, 2), 'B'
)
WHEN LENGTH(ROUND(SUM(`Total`), 0)) >= 7 THEN
CONCAT(
ROUND(SUM(`Total`) / 1000000, 2), 'M'
)
WHEN LENGTH(ROUND(SUM(`Total`), 0)) >= 4 THEN
CONCAT(
ROUND(SUM(`Total`) / 1000000, 2), 'K'
)
WHEN LENGTH(ROUND(SUM(`Total`), 0)) <= 3 THEN
ROUND(SUM(`Total`), 0)
WHEN SUM(`Total`) IS NULL THEN 0
ELSE 'ERROR'
END)With you example though you'd want to replace SUM(`Total`) with your beast mode to calculate the total $ amount.
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**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