MTD, MTD Last Year Beastmodes do not work properly with Date filter
I created 2 Beastmodes that I can drag into the 'Values' in the Pivot Table card:
MTD = SUM(CASE
WHEN Month
= MONTH(CURRENT_DATE()) AND Year
= YEAR(CURRENT_DATE()) THEN IFNULL(Amount
* -1, 0)
ELSE 0
END)
MTD Last Year = SUM(CASE
WHEN Month
= MONTH(CURRENT_DATE()) AND Year
= YEAR(CURRENT_DATE()) - 1 THEN IFNULL(Amount
* -1, 0)
ELSE 0
END)
I don't have October data, so the MTD is 0.00
Then I created a year & a month dropdown selector (with the same dataflow) and randomly picked a month, year. But MTD and MTD Last Year show all 0.00
But if specify the exact month and year in my Beastmode, the pivot card does show the correct number (however, with this, I cannot dynamically filter month, year)
Comments
-
There are a couple things going on
1. I'd recommend that Month and Year be variables, it sounds like they are filter cards built off the same dataset as your MTD/Last Year MTD card
2. Assuming that they are filter cards, then when you choose a Month and Year this filters your data to a single month and year which would explain why the Last Year MTD beast mode isn't returning the correct results
3. Your MTD beast mode will only calculate a non-zero value for the Current Month and Year
4. If Month and Year are already variables, that's great then you just need to add another beast mode that you will place in your filters:
CASE WHEN <month variable name> = month(<your date field>) AND (<year variable name> = year(<your date field>) OR year(<your date field>) = (<year variable name>-1)) THEN 'Include' ELSE 'Exclude' END
then filter the card on 'Include', this will give you the selected month and year, and also the same month for the prior year
Finally, you have to update your MTD and MTD Last Year beast modes:
— MTD SUM(CASE
WHEN <month variable name> = MONTH(<your date field>) AND <year variable name> = YEAR(<your date field>) THEN Amount * -1
END)
— MTD Last Year SUM(CASE
WHEN <month variable name> = MONTH(<your date field>) AND <year variable name>-1 = YEAR(<your date field>) THEN Amount * -1
END)1 -
Thank you so much, I'll try this. I haven't created any variables before so quick questions on creating them.
So right now I only have data from Feb 2023 - Sep 2024, but I'll update this dataset in the future. When picking a year it should start from 2024 onwards, do I need to add 2025, 2026 in the variable right now, or I could add/change it in the future?And for the Month variable, would you suggest to create a Month Number or Month Name? I would like to see 'Jan', 'Feb' in order when I'm picking the Month filter.
And for the default value, can you do YEAR(CURRENT_DATE()) or MONTH(CURRENT_DATE())?
I'm planning on having a YTD and YTD Last Year columns as well, is it still applicable?0 -
Variables are pretty awesome, especially for the sort of reporting you're doing where there are a fixed set of months that will never have to change and a limited number of years that need to be updated infrequently.
Regarding your questions:
- You can update the years at any time
- What I sent earlier assumed a month number, but I can see how a name works better for the variable. I'd suggest populating it with month names and then update the beast modes with
<month variable name> = MONTHNAME(<your date field>)
3. the Default Value can't be an expression unfortunately, but you could add a month to your variable called 'Current Month' and then have your beast mode handle it that way
4. YTD/YTD Last Year would require and update to the filtering beast mode, so that it returns full years rather that specific month and years. One way to handle it would be to update the beast mode if you think your users are going to be selecting years often. But another way to handle it would be to just save your card with Last Two Years selected as the date range, going this route would eliminate the need for the Year variable.
1 -
Thank you for your answer, it was very helpful. However, I don't quite understand this BeastMode:
CASE
WHEN <month variable name> = month(<your date field>)
AND (<year variable name> = year(<your date field>) OR year(<your date field>) = (<year variable name>-1))
THEN 'Include'
ELSE 'Exclude'
END
Isn't it doing the same thing with the MTD/MTD Last Year Beastmode already with the Case When?
1 -
You're right, in hindsight it does seem redundant! I guess I was thinking by minimizing the rows by filtering would ensure that you'd get the correct results. However, now especially because you want to add YTD on the same card it seems like you can handle it all without any special filtering.
1
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 737 Beast Mode
- 55 App Studio
- 40 Variables
- 684 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 123 Manage
- 120 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