Previous Month Last Year value Formula
Hi Everyone
I'm trying to calculate a sum of values for the previous month for the previous year (February 2024 in this case) so that I can compare the difference to previous month for this year
I've made a few attempts but have had no success
What is the best way to do this calculation for last year previous month?
Thanks
Dan
Answers
-
Hi @_DanielB_ , I would recommend using one of Domos period over period charts:
If I solved your problem, please select "yes" above
0 -
I need to create the formula in the ETL as I have to include it in other calculations in my output dataset
I tried the below but that didn't return any values and there are definitely values for last year
CAST(
CASE WHEN YEAR(`Month`) = YEAR(CURDATE()) -1 AND MONTH(`Month`) = MONTH(CURDATE()) -1 THEN
CAST(
CASE
WHENCost_Type
IN ('Profit', 'Costs') ANDCTYPE
IN ('EXP', 'INC') THENCost (£)
ELSE
'0'
END
AS DECIMAL
)
ELSE
0
END
AS DECIMAL
)0 -
Gotcha. I would recommend using a LAG function
- Structure your data to look something like this:
Month
Amount
01/01/2024
100
02/01/2024
103
03/01/2024
105
04/01/2024
110
05/01/2024
115
06/01/2024
116
07/01/2024
120
08/01/2024
126
09/01/2024
129
10/01/2024
135
11/01/2024
139
12/01/2024
120
01/01/2025
140
02/01/2025
146
03/01/2025
149
2. Use LAG to get the previous year value as a new field, `1YearPreviousAmount`
Month
Amount
1YearPreviousAmount
01/01/2024
100
02/01/2024
103
03/01/2024
10504/01/2024
110
05/01/2024
115
06/01/2024
116
07/01/2024
120
08/01/2024
126
09/01/2024
129
10/01/2024
135
11/01/2024
139
12/01/2024
120
01/01/2025
140
100
02/01/2025
146
103
03/01/2025
149
105More info here:
scroll down to the "Offset Functions" sectionIf I solved your problem, please select "yes" above
1 -
Thanks @ColemenWilson I'll give that a try :)
0 -
This should work. I'm using it on many occasions:
Value Previous Month:
SUM(CASE
WHEN YEAR(CURRENT_DATE()) = YEAR(`SALES_DATE`) AND MONTH(CURRENT_DATE()) - 1 = MONTH(`SALES_DATE`) THEN `SALES_AMOUNT`
ELSE 0
END)Value Last Fiscal Year Same Month:
SUM(CASE
WHEN YEAR(CURRENT_DATE())-1 = YEAR(`SALES_DATE`) AND MONTH(CURRENT_DATE()) - 1 = MONTH(`SALES_DATE`) THEN `SALES_AMOUNT_HC`
ELSE 0
END)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
- 193 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