Calculation of previous dated values

I am trying to calculate trailing period (previous period) calc. I have year(variable selector), month(dropdown selector chart using column from table)
If i select Year = 2024 and Month = Feb, I should get the data for 2024-JAN.
Tried this formula but failing to get the correct figure. RecordDate(date format col) is another column holds the last day of the month. (Date -format column).
SUM(
CASE
WHEN
-- If selected year+month, trailing period is same year but previous month
Year = YrSelector AND Month = MONTH(RecordDate) THENSalesValue
/* Previous month */ WHEN
-- If no additional selection, trailing period is previous year
(`Year` = `YrSelector` - 1) AND `Month` IS NULL THENSalesValue
/* Previous year */
ELSE 0
END )
Answers
-
It looks like your first condition isn't looking for the previous month.
WHEN Year = YrSelector AND 'Month' = MONTH(DATE_SUB(RecordDate, INTERVAL 1 MONTH)) THEN SalesValue
If your data crosses Dec 2023 and Jan 2024, you'll also likely need something for that condition.
WHEN Year = YrSelector - 1 AND 'Month' = 12 AND YrSelector = 2024 AND MONTH(RecordDate) = 1 THEN SalesValue
Hope this helps :)
1 -
@Luke_Mielke - I have tried doing a DATE_SUB, still no luck. For some reason it is not picking the calc. If I hard-code it with prev month number , it prints the value. something like,
Let's say my current month is 2. If i pass 1, it gives value but not able to make it dynamic.
WHEN Year = YrSelector AND 'Month' = 1) THEN SalesValue
0
Categories
- All Categories
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 308 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 3.8K Transform
- 660 Datasets
- 117 SQL DataFlows
- 2.2K Magic ETL
- 815 Beast Mode
- 3.3K Visualize
- 2.5K Charting
- 84 App Studio
- 46 Variables
- 779 Automate
- 191 Apps
- 482 APIs & Domo Developer
- 83 Workflows
- 23 Code Engine
- 41 AI and Machine Learning
- 20 AI Chat
- 1 AI Playground
- 2 AI Projects and Models
- 18 Jupyter Workspaces
- 413 Distribute
- 121 Domo Everywhere
- 281 Scheduled Reports
- 11 Software Integrations
- 145 Manage
- 141 Governance & Security
- 8 Domo Community Gallery
- 49 Product Releases
- 12 Domo University
- 5.4K Community Forums
- 41 Getting Started
- 31 Community Member Introductions
- 115 Community Announcements
- 4.8K Archive