Forum Discussion
Trailing Months Cumulative Sum with Disconnected Date Table
Hello,
I posted a version of this an hour ago that was more detailed but it seems to have not saved (but if you see a version of it out there, let me know!)
I am trying to find a solution that modifies the trailing months DAX used in this link: Show previous 6 months of data from single slicer selection - SQLBI
Instead of the "SELECTEDMEASURE()" function, however, I would replaced with an established measure that works well without a disconnected date table and slicer for end of month. I would also modify from 6 months to 12 months.
I have used the above formula many times to convert my non-dynamic values into dynamic trailing values. It works fine in my current project for basic monthly totals, however, I'm trying to find a solution for it to calculate Cumulative Sum. Nothing I have tried works including spending a day with ChatGPT. It will either still give me the monthly total, or does not limit the result to trailing 12 months, and gives the same value across all months.
I need the result to cumulate the total for the past 12 months for each month listed in a matrix visualization. So if the user selects March 2024, I would want the monthly total for March 2024 plus all months back to April 2023. If the user selects January 2024, it should be the cumulative total back to Feb 2023. But it should also show the cumulative total for the Dec 2023, Nov 2023, etc in the matrix even though you won't see all 12 months prior for all months displayed.
Sorry, I had a visual version of this to explain better, but apparently it was deleted. If this doesn't make sense I can try to replicate tomorrow, but wanted to post this in case anyone has some good ideas overnight (here).
ETA: I added some mock up data and more context in a comment below.
Thanks!
6 Replies
- Ashish_Mathur
Super User
Hi,
Share data in a format that can be pasted in an MS Excel file and show the expected result.
- mbahonen
Advocate II
Hi, yes, sorry. As mentioned my first post with that was apparently not posted, and I had deleted my mock up. Here is a sample of what I'm looking for.
I need a dynamic rolling measure ideally similar to the one in the link of my OP with a disconnected date table and a user impacted on page slicer to calculate the 12M Cumulative Total. Right now the results I'm getting are just the Total. I've tried about 10 variations. Nothing seems to take the 12M history cumulative total into account. The visualization (matrix table but could be bar chart, etc) will display 12 only months with the latest date the user selected date (month year), and the earliest date 12 months earlier, but the data needs to pull from as much as is available on a rolling 12M basis.
Month Year Total 12M Cumulative Total March 2024 50 440 Feb 2024 45 435 Jan 2024 60 430 Dec 2023 20 425 Nov 2023 30 420 Oct 2023 15 415 Sep 2023 75 410 Aug 2023 5 405 Jul 2023 35 400 Jun 2023 40 395 May 2023 10 390 Apr 2023 55 385 March 2023 45 340 Feb 2023 40 12M history not availble Jan 2023 55 12M history not availble Dec 2022 15 12M history not availble Nov 2022 25 12M history not availble Oct 2022 10 12M history not availble Sep 2022 70 12M history not availble Aug 2022 0 12M history not availble Jul 2022 30 12M history not availble Jun 2022 35 12M history not availble May 2022 5 12M history not availble Apr 2022 10 12M history not availble End of Known Data - Ashish_Mathur
Super User
I am just unable to understand your question. Do not point to another link please. Just explain the question is simple English.
- mbahonen
Advocate II
More context:
Here is my original measure and the new measure that is the most promising so far, but that does not yet give the cumulative total, only the individual total (this is about the 10th version I've tried):
Original:
12M Cumulative Sum =
VAR StartDate =
NEXTMONTH ( LASTDATE ( DATEADD ( 'FactTable’[ReportDate], -12, MONTH ) ) )
VAR EndDate =
LASTDATE ( 'FactTable’[ReportDate])
RETURN
CALCULATE (
SUM ( FactTable[RecordCount] ),
DATESBETWEEN ( 'FactTable’[ReportDate], StartDate, EndDate )
)
Current Front-runner dynamic wrapper:
12M Cumulative Sum LOOKBACK WIP 2 - DOES NOT WORK =
VAR StartDate =
NEXTMONTH ( LASTDATE ( DATEADD ( 'FactTable’[ReportDate], -12, MONTH ) ) )
VAR EndDate =
LASTDATE ( FactTable[ReportDate])
VAR Results =
CALCULATE( SUMX(FactTable, FactTable[RecordCount] ),
DATESBETWEEN ( FactTable[ReportDate], StartDate, EndDate ), TREATAS( VALUES('Calendar LOOKBACK'[Date]), 'Calendar'[Date] ))
RETURN
Results
- mbahonen
Advocate II
Here is some more context and info for what I've tried so far.
This is my original Non-Dynamic measure that accurately gives me the cumulative 12M sum (but does not work with user interactive slicers):
12M Cumulative Sum =
VAR StartDate =
NEXTMONTH ( LASTDATE ( DATEADD ( 'FactTable’[ReportDate], -12, MONTH ) ) )
VAR EndDate =
LASTDATE ( 'FactTable’[ReportDate])
RETURN
CALCULATE (
SUM ( FactTable[RecordCount] ),
DATESBETWEEN ( 'FactTable’[ReportDate], StartDate, EndDate )
)
Attempt for Rolling Measure 1: Dynamic Rolling 12M Wrapper (DOES NOT WORK)
- I have used this version for simpler measure many times and it works with other measure in my current report that only care about individual monthly totals.
- Does not work with for [12M Cumulative Sum]; gives a weird cumulative total I haven’t figured out, but it does “wrap dynamically” in that it limits the values to the 12M rolling period
- It also gives the correctly monthly Total (see sample data) value in the dynamic maxtrix (BUT does not correctly give the cumulative sum in the non-dynamic matrix per previous bullet)
12M Cumulative Sum LOOKBACK WIP 1 =
VAR ReferenceDate = MAX ('Calendar'[Date])
VAR PreviousDate =
DATESINPERIOD(
'Calendar LOOKBACK'[Date],
ReferenceDate,
-12,
MONTH
)
VAR Results =
CALCULATE (
[12M Cumulative Sum],
REMOVEFILTERS('Calendar'),
KEEPFILTERS(PreviousDate),
USERELATIONSHIP('Calendar'[Date], 'Calendar LOOKBACK'[Date])
)
RETURN
Results
Attempt for Rolling Measure 2: Dynamic Rolling 12M Wrapper (PARTIALLY WORKS)
- This version same version I found in the link referenced below. It’s the ONLY version I’ve tried in the last day that gives the correct cumulative value in the non-dynamic table, but still only gives the monthly total in the dynamic table. I think this is on the right track but still doesn’t give cumulative totals in the dynamic version, only the original non-dynamic version of the visualization. In the dynamic matrix it will just show the individual month totals (like so many of the other versions I've tried).
12M Cumulative Sum LOOKBACK WIP 2 =
VAR StartDate =
NEXTMONTH ( LASTDATE ( DATEADD ( 'FactTable’[ReportDate], -12, MONTH ) ) )
VAR EndDate =
LASTDATE ( FactTable[ReportDate])
VAR Results =
CALCULATE( SUMX(FactTable, FactTable[RecordCount] ),
DATESBETWEEN ( FactTable[ReportDate], StartDate, EndDate ), TREATAS( VALUES('Calendar LOOKBACK'[Date]), 'Calendar'[Date] ))
RETURN
Results