Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
JakeHRogers
Frequent Visitor

Running total but stop after the last value in the fact table (solutions tried break running total)

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):

 

JakeHRogers_0-1717080789808.png

 

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:

 

JakeHRogers_1-1717081126906.png

 

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

2 ACCEPTED SOLUTIONS
sjoerdvn
Super User
Super User

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)
)

View solution in original post

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)
)

View solution in original post

14 REPLIES 14
sjoerdvn
Super User
Super User

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.

JakeHRogers_0-1717160144439.png

 



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!

sjoerdvn
Super User
Super User

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]))
sjoerdvn
Super User
Super User

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)
)

Still no joy 😞

JakeHRogers_0-1717149485535.png

 

This dropbox link should work:

https://www.dropbox.com/t/yqNdgpW40NocCAgU 


sjoerdvn
Super User
Super User

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.

sjoerdvn
Super User
Super User

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):

JakeHRogers_0-1717146708787.png

 

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 

sjoerdvn
Super User
Super User

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:

JakeHRogers_0-1717084623657.png

 

Alex87
Solution Sage
Solution Sage

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
    )
)



Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!




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:


JakeHRogers_1-1717084816690.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors