Best mode - combine MTD and YTD
Hi there!
I have a problem with beast mode. I think the solution is easy, but I can´t figure out the correct function in beast mode.
We need to display sales of our team. Therefore I created a table with team names and sales MTD and Sales YTD.
My datasource includes a field called season (our business year is from May till April next year) which I use for my Sales YTD.
Unfortunately, I can´t figure out the MTD part, which is always based on the current month.
I tried this function in beast mode:
(CASE
when MONTH(`Datum`)=MONTH(CURRENT_DATE()) and YEAR(`Datum`)=YEAR(CURRENT_DATE()) then
SUM((CASE when `Total` is null then 0 else `Total` end))
else 0
end)
In return I always get 0 per person. If I add "this month" in my card builder the function works, but my YTD doesn´t anymore.
Do I need to add something in my MTD formula, because I think I have an issue with identifying dates (maybe?).
I wasn´t able to find anything close in other thread.
Many thanks for helping me!
BR
Best Answer
-
I would try pulling the aggregate out of the case statement.
sum(CASE
when MONTH(`Datum`)=MONTH(CURRENT_DATE()) and YEAR(`Datum`)=YEAR(CURRENT_DATE()) then
ifnull(`Total`,0)
else 0
end)
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1
Answers
-
I would try pulling the aggregate out of the case statement.
sum(CASE
when MONTH(`Datum`)=MONTH(CURRENT_DATE()) and YEAR(`Datum`)=YEAR(CURRENT_DATE()) then
ifnull(`Total`,0)
else 0
end)
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1 -
Thank you for your help Superman!!
I don´t really understand why my function didn´t work out, but yours did!
1 -
A case statement works through your data one row at a time. It looks for the first "when" statement that is correct and then evaluates the "then" expression. If no when statement is true then it goes to an "else" statement or returns a null value.
In your case, you had one when clause and an else statment. So, when it evaluated the expression, the first row of data did not meet the when clause (month and year) so it went ahead to the else statment and returned 0.
by pulling the aggregate sum() function outside of the case statement, you are telling the case statement to continue running for all rows of data and then sum all of the results.
Hope that helps. Let me know if you have more questions.
“There is a superhero in all of us, we just need the courage to put on the cape.” -Superman1 -
Thanks for helping me out!
I think I understand your solution.
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 618 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 741 Beast Mode
- 58 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 395 Distribute
- 113 Domo Everywhere
- 276 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive