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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ansa_naz
Continued Contributor
Continued Contributor

Calculate a running total with an opening balance

I have the following example data:

DateAmountRunning Total
01/08/20181611116111
01/09/20181507031181
01/10/2018736138542
01/11/2018460043142
01/12/20182486268004
01/01/20191020078204
01/02/2019232080524
01/03/20191369294216
01/04/20195938100154
01/05/20192656102810
01/06/201919550122360
01/07/201915363137723
01/08/201922155159878
01/09/201922426182304
01/10/201918693200997
01/11/201912066213063
01/12/201911414224477
01/01/20203130227607
01/02/20209849237456
01/03/20207908245364
01/04/202012724258088

My running total calculatiuon works fine if I show all the data in a chart:

 

Running Total = 
CALCULATE(
	SUM('Stats'[Amount]),
	FILTER(
		ALL('Stats'[Date]),
		ISONORAFTER('Stats'[Date], MAX('Stats'[Date]), DESC)
	)
)

 

However I want to show all data for the last 12 months and all data in the future:

DateAmountRunning Total
01/12/20182486268004
01/01/20191020078204
01/02/2019232080524
01/03/20191369294216
01/04/20195938100154
01/05/20192656102810
01/06/201919550122360
01/07/201915363137723
01/08/201922155159878
01/09/201922426182304
01/10/201918693200997
01/11/201912066213063
01/12/201911414224477
01/01/20203130227607
01/02/20209849237456
01/03/20207908245364
01/04/202012724258088

Any ideas how I could go about doing that, and have the running total formula show the correct amount?

Cheers for all help

 

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

@ansa_naz 

try

Running Total Measure = 
var startPeriod = DATE(YEAR(EOMONTH(TODAY();-12));MONTH(EOMONTH(TODAY();-12));1)
return 
if(
SELECTEDVALUE(Stats[Date])>startPeriod;
CALCULATE(
	SUM('Stats'[Amount]);
	FILTER(
		ALL('Stats'[Date]);
		ISONORAFTER('Stats'[Date]; MAX('Stats'[Date]);DESC) 
	)
);
BLANK()
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

7 REPLIES 7
az38
Community Champion
Community Champion

Hi @ansa_naz 

try a measure

Running Total Measure = 
var startPeriod = DATE(YEAR(EOMONTH(TODAY();-12));MONTH(EOMONTH(TODAY();-12));1)
return CALCULATE(
	SUM('Stats'[Amount]);
	FILTER(
		ALL('Stats'[Date]);
		ISONORAFTER('Stats'[Date]; MAX('Stats'[Date]);DESC) && 'Stats'[Date]>startPeriod
	)
)

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
ansa_naz
Continued Contributor
Continued Contributor

Hi @az38  if I use this then the Running Total does not include the Amount from before 12 months ago - in effect the Running Total resets from 12 months ago, but it should include all values before that date too, just not display it

az38
Community Champion
Community Champion

@ansa_naz 

really? i think its exactly running total of amount. or how do you wanna calculate it?

425112.png

do not hesitate to give a kudo to useful posts and mark solutions as solution

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
ansa_naz
Continued Contributor
Continued Contributor

Hi @az38  if I use this then the Running Total does not include the Amount from before 12 months ago - in effect the Running Total resets from 12 months ago, but it should include all values before that date too, just not display it

ansa_naz
Continued Contributor
Continued Contributor

I think the below makes more sense?

 

nDRM7rovFV.jpg

 
az38
Community Champion
Community Champion

@ansa_naz 

try

Running Total Measure = 
var startPeriod = DATE(YEAR(EOMONTH(TODAY();-12));MONTH(EOMONTH(TODAY();-12));1)
return 
if(
SELECTEDVALUE(Stats[Date])>startPeriod;
CALCULATE(
	SUM('Stats'[Amount]);
	FILTER(
		ALL('Stats'[Date]);
		ISONORAFTER('Stats'[Date]; MAX('Stats'[Date]);DESC) 
	)
);
BLANK()
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
ansa_naz
Continued Contributor
Continued Contributor

Brilliant! Cheers @az38 !

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.