MTD and MTD Last Year, leap year problem

I want to show sales MTD and MTD Last Year as of Feb 28, 2025 so I created Beast Mode:
MTD = CASE WHEN CURRENT_DATE >= SHIP_DATE and CURRENT_DATE <= LASTDAY(SHIP_DATE) THEN 'sales_amount' ELSE 0 END
MTD Last Year = CASE WHEN DATE_ADD(CURRENT_DATE, INTERVAL -1 YEAR) >= SHIP_DATE AND DATE_ADD(CURRENT_DATE, INTERVAL -1 YEAR) <= LASTDAY(SHIP_DATE) THEN 'sales_amount' ELSE 0 END
If my CURRENT_DATE is Feb 28, 2024. MTD would show me sales from Feb 1 - 28, 2025, which is correct. MTD Last Year shows me sales from Feb 1 - 28, 2024 but I need it to show me Feb 1- 29, 2024.
So ideally, if the Current Date is the last day of the month, MTD and MTD Last Year should show sales for that entire month of the Current Date
Answers
-
Hello @verytiredgirl,
You can try with nested CASE statements and first check if the current day is the last day of the month:
CASE
WHEN CURRENT_DATE() = LAST_DAY(CURRENT_DATE()) THEN
CASE
WHEN MONTH(CURRENT_DATE()) = MONTH(SHIP_DATE) AND YEAR(CURRENT_DATE()) = YEAR(SHIP_DATE)
THEN 'sales_amount'
ELSE 0
END
ELSE [your CASE statement]
For the MTD Last year will be something like this:
CASE
WHEN CURRENT_DATE() = LAST_DAY(CURRENT_DATE()) THEN
CASE
WHEN MONTH(CURRENT_DATE()) = MONTH(SHIP_DATE) AND YEAR(CURRENT_DATE()) - 1 = YEAR(SHIP_DATE)
THEN 'sales_amount'
ELSE 0
END
ELSE [your CASE statement]
If you found this post helpful, please use 💡/💖/👍/😊 below! If it solved your problem, don't forget to accept the answer.
0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 310 Workbench
- 7 Cloud Amplifier
- 9 Federated
- 3K Transform
- 113 SQL DataFlows
- 651 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 795 Beast Mode
- 78 App Studio
- 44 Variables
- 755 Automate
- 187 Apps
- 480 APIs & Domo Developer
- 71 Workflows
- 17 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 407 Distribute
- 118 Domo Everywhere
- 279 Scheduled Reports
- 10 Software Integrations
- 141 Manage
- 137 Governance & Security
- 8 Domo Community Gallery
- 47 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 113 Community Announcements
- 4.8K Archive