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
- Product Ideas
- 2.1K Ideas Exchange
- Connect
- 1.3K Connectors
- 309 Workbench
- 7 Cloud Amplifier
- 10 Federated
- Transform
- 663 Datasets
- 119 SQL DataFlows
- 2.3K Magic ETL
- 823 Beast Mode
- Visualize
- 2.6K Charting
- 86 App Studio
- 46 Variables
- Automate
- 194 Apps
- 483 APIs & Domo Developer
- 87 Workflows
- 23 Code Engine
- AI and Machine Learning
- 23 AI Chat
- 4 AI Projects and Models
- 18 Jupyter Workspaces
- Distribute
- 117 Domo Everywhere
- 283 Scheduled Reports
- 11 Software Integrations
- Manage
- 143 Governance & Security
- 11 Domo Community Gallery
- 49 Product Releases
- 13 Domo University
- Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 116 Community Announcements
- 5K Archive