Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hello,
I am trying to create a cumulative total measure that stops after the last transaction in the fact table (the date in the date dimension table continues into the future):
The current measure (without trying to stop the cumulative total):
Total Price running total in DateKey =
CALCULATE(
SUM('Fact Transaction'[Total Price]),
FILTER(
CALCULATETABLE(
SUMMARIZE(
'Dim YearMonth'
,'Dim YearMonth'[Sort]
,'Dim YearMonth'[DateKey]
),
ALLSELECTED('Dim YearMonth')
),
ISONORAFTER(
'Dim YearMonth'[Sort], MAX('Dim YearMonth'[Sort]), DESC,
'Dim YearMonth'[DateKey], MAX('Dim YearMonth'[DateKey]), DESC
)
)
)
After reviewing other posts on the forum, I tried to stop the cumulative total by adding:
&& 'Dim YearMonth'[DateKey] <= MAX('Fact Transaction'[Date Key])
Like this:
Total Price running total in DateKey =
CALCULATE(
SUM('Fact Transaction'[Total Price]),
FILTER(
CALCULATETABLE(
SUMMARIZE(
'Dim YearMonth'
,'Dim YearMonth'[Sort]
,'Dim YearMonth'[DateKey]
),
ALLSELECTED('Dim YearMonth')
),
ISONORAFTER(
'Dim YearMonth'[Sort], MAX('Dim YearMonth'[Sort]), DESC,
'Dim YearMonth'[DateKey], MAX('Dim YearMonth'[DateKey]), DESC
)
&& 'Dim YearMonth'[DateKey] <= MAX('Fact Transaction'[Date Key])
)
)
That worked but it caused issues with the cumulative total - any months with no transactions now do not show the cumulative total unlike before:
I have created a mock PBIX with the data - any help on this would be much appreciated as sunk a lot of time into it now:
Running Total Issue.pbix
Thanks
Solved! Go to Solution.
if you want to retain the filter on item3, try this:
sjoerdvn =
VAR dis = ALLSELECTED('Dim Item')
VAR ldf = CALCULATE(MAX('Dim YearMonth'[Sort]), ALL('Dim YearMonth'),TREATAS(CALCULATETABLE(VALUES('Fact Transaction'[Date Key]), ALL(), dis), 'Dim YearMonth'[DateKey]))
VAR lds = MAX('Dim YearMonth'[Sort])
RETURN
IF (lds <= ldf
,CALCULATE(
SUM('Fact Transaction'[Total Price]),
ALL('Dim YearMonth'),
'Dim YearMonth'[Sort] <= lds)
)
I was assuming that was what you wanted...
try this
sjoerdvn =
VAR ldf = CALCULATE(MAX('Dim YearMonth'[Sort]), ALL('Dim YearMonth'),TREATAS(CALCULATETABLE(VALUES('Fact Transaction'[Date Key]),ALL('Dim YearMonth')), 'Dim YearMonth'[DateKey]))
VAR lds = MAX('Dim YearMonth'[Sort])
RETURN
IF (lds <= ldf
,CALCULATE(
SUM('Fact Transaction'[Total Price]),
ALL('Dim YearMonth'),
'Dim YearMonth'[Sort] <= lds)
)
if you want to retain the filter on item3, try this:
sjoerdvn =
VAR dis = ALLSELECTED('Dim Item')
VAR ldf = CALCULATE(MAX('Dim YearMonth'[Sort]), ALL('Dim YearMonth'),TREATAS(CALCULATETABLE(VALUES('Fact Transaction'[Date Key]), ALL(), dis), 'Dim YearMonth'[DateKey]))
VAR lds = MAX('Dim YearMonth'[Sort])
RETURN
IF (lds <= ldf
,CALCULATE(
SUM('Fact Transaction'[Total Price]),
ALL('Dim YearMonth'),
'Dim YearMonth'[Sort] <= lds)
)
Thank you so much @sjoerdvn - the only issue is that the running total finishes for every line at the last transaction of the item that has the latest transaction date.
However, I'm accepting your reply as solution because it's a significant improvement on what I've been able to achieve so far!
I was assuming that was what you wanted...
try this
sjoerdvn =
VAR ldf = CALCULATE(MAX('Dim YearMonth'[Sort]), ALL('Dim YearMonth'),TREATAS(CALCULATETABLE(VALUES('Fact Transaction'[Date Key]),ALL('Dim YearMonth')), 'Dim YearMonth'[DateKey]))
VAR lds = MAX('Dim YearMonth'[Sort])
RETURN
IF (lds <= ldf
,CALCULATE(
SUM('Fact Transaction'[Total Price]),
ALL('Dim YearMonth'),
'Dim YearMonth'[Sort] <= lds)
)
10/10! Thank you so much - now I can spend the afternoon understanding what you did!
I see.
If you want to include the months where item3 has a value, then change the first line to this:
VAR ldf = CALCULATE(MAX('Dim YearMonth'[Sort]), ALL('Dim YearMonth'),TREATAS(CALCULATETABLE(VALUES('Fact Transaction'[Date Key]), ALL()), 'Dim YearMonth'[DateKey]))
Also, note that that PBIX cannot be downloaded from there...
Total Price running total in DateKey =
VAR ldf = CALCULATE(MAX('Dim YearMonth'[Sort]), ALL(), CROSSFILTER('Fact Transaction'[DateKey],'Dim YearMonth'[DateKey],Both))
VAR lds = MAX('Dim YearMonth'[Sort])
RETURN
IF (lds <= ldf
CALCULATE(
SUM('Fact Transaction'[Total Price]),
ALL('Dim YearMonth'),
'Dim YearMonth'[Sort] <= lds)
)
I see. So it is not a date dimension. Also, we can't use the datekey for determining the cumulative values. For efficiency I would recommand using a key that is sorted, because now we need an extra lookup. will post some dax below.
what does your date dimension table look like? I was assuming the DateKey was either a date or an integer number.
@sjoerdvn , the DateKey is a text field (concatenation of year, hyphen and month):
I can't use a normal date field because my user's requirements mean that I have to set the year as 1, 2, 3 etc so I can layer items from different years on top of each other on a line chart depending on whether it's their first year of existence, second year of existence etc.
If I change the reference from [DateKey] to [Sort] it works but if there's another item in the dataset with a longer date range, which I don't want to show in the chart, the values don't stop again (until the end of the date range of the item excluded on the chart)
I have a mock .pbix set up here: PBIX
Just calculate the max date in the fact table first, ignoring all filters.
Also, I think the measure can be a lot simpler
Total Price running total in DateKey =
VAR ldf = CALCULATE(MAX('Fact Transaction'[Date Key]), ALL())
VAR lds = MAX('Dim YearMonth'[DateKey])
RETURN
IF (lds <= ldf
CALCULATE(
SUM('Fact Transaction'[Total Price]),
ALL('Dim YearMonth'),
'Dim YearMonth'[DateKey] <= lds)
)
Hi @sjoerdvn ,
Please see screenshot below after implementation. The cumulative total seems to stop working and values begin to appear for e.g. '1-Jan' despite this period pre-dating the start of transactions for either item:
CumulativeTotal =
VAR LastTransDate = [LastTransactionDate] (here you calculate last transaction date with Calculate ..ALL)
RETURN
CALCULATE(
SUM('FactTable'[Amount]),
FILTER(
ALLSELECTED('DateTable'),
'DateTable'[Date] <= MAX('DateTable'[Date]) &&
'DateTable'[Date] <= LastTransDate
)
)
Hi @Alex87 ,
Please see implementation in screenshot below. The cumulative total seems to stop working and values seem to appear for e.g. '1-Jan' despite this period pre-dating the start of transactions for either item:
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!