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
- 2K Product Ideas
- 2K Ideas Exchange
- 1.6K Connect
- 1.3K Connectors
- 310 Workbench
- 7 Cloud Amplifier
- 9 Federated
- 3K Transform
- 113 SQL DataFlows
- 654 Datasets
- 2.2K Magic ETL
- 4K Visualize
- 2.5K Charting
- 796 Beast Mode
- 78 App Studio
- 44 Variables
- 757 Automate
- 188 Apps
- 480 APIs & Domo Developer
- 72 Workflows
- 17 DomoAI
- 40 Predict
- 17 Jupyter Workspaces
- 23 R & Python Tiles
- 408 Distribute
- 119 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
- 114 Community Announcements
- 4.8K Archive