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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
matthewsignal
Frequent Visitor

Cumulative sum of a measure which calculates a cumulative sum

Hi there, 

I am a new user of Power BI and I am trying to learn about measures and DAX etc

I am trying to create a cumulative sum of a measure that itself calculates a cumulative sum (all of which needs to be sliceable).

A table view of the data/measures I have created is follows:

table.PNG

Where: 

Age column is pulled in straight from a Table. 

 

Total Assets is a simple measure: Total Assets = COUNT(Assets[Age]) + 0

 

Cumulative Assets was generated using the quick measure running total: 

 

Cumulative Assets =
CALCULATE(
[Total Assets],
FILTER(
ALLSELECTED('Age Table'[Age]),
ISONORAFTER('Age Table'[Age], MAX('Age Table'[Age]), ASC)
)
)

 

Total Faults is a simple measure: Total Faults = COUNT(Faults[Age at Fault]) + 0

 

Fault Rate is a simple measure: Fault Rate = DIVIDE([Total Faults],[Cumulative Assets]) + 0

 

The desired goal is to have "Cumulative Fault Rate" calculate a running total of the Fault Rate as a function of age. 

The column should contain [0.27, 0.47, 0.87, 0.87, 0.87...]

 

I have tried to implement using the quick measure running total: 

Cumulative Fault Rate =
CALCULATE(
[Fault Rate],
FILTER(
ALLSELECTED('Age Table'[Age]),
ISONORAFTER('Age Table'[Age], MAX('Age Table'[Age]), DESC)
)
)

 

As the table shows, the "Cumulative Fault Rate" column is not showing what I want.... 

 

Finally, I would like the measures to be dynamic with the model slicer (I am assuming that is where the "ALLSELECTED" function fits in....)

 

Apologies if this has been covered, I did read a couple of other threads and tried to solve on my own...but couldn't get it working. 

Thanks,

Matt 

9 REPLIES 9
bisucks
Frequent Visitor

All these only work with columns and not measures. Quite useless.

v-xjiin-msft
Solution Sage
Solution Sage

Hi @matthewsignal,

 

To make a cumulative sum on a measure, you can try following measure:

 

Cumulative Fault Rate =
SUMX (
    FILTER (
        ALLSELECTED ( 'Age Table'[Age] ),
        'Age Table'[Age] <= MAX ( 'Age Table'[Age] )
    ),
    [Fault Rate]
)

8.PNG

 

Thanks,
Xi Jin.

Hi,
thanks for your measure, actually i almost get what i want with this measure.

 

how can i recalculate it when it starts next year?

 

NewbieDAX123_1-1669050045298.png

 

 

Hi @v-xjiin-msft,

thanks for your fast response. 

Unfortunately that hasn't worked for me, see result below .

table2.PNG

 

 

The result has changed compared to my first attempt, but still not correct.

Did you enter the fault rate data in a table or calcuate it via the equations I posted originally when developing your solution? 

I am keen to hear any further ideas anyone has on how to solve this. 

Many thanks,

Matt 

 

 

Hi @matthewsignal,

 

Since I can't see your real data and you have only shared some measure results. It is hard for me to repro your issue. Could you please share us your pbix file with One Drive or Google Drive if possible? So that I can get a right direction.

 

If you can't, please share some sample data which I can copy and paste directly.

 

Thanks,
Xi Jin.

Hi @v-xjiin-msft,

Yes sure, I have uploaded the pbix file to dropbox, see the link: 

 

https://www.dropbox.com/s/sgpxnx1buf28e7h/cumul%20sum%20data.pbix?dl=0 

 

It is a very basic data set to illistrate the challenge I am having. 

Let me know if you have any questions.

thanks,

Matt

Hi @matthewsignal,

 

OK. I got it. The issue is on the Cumulative Assets formula. The order of this cumulative is from bigger Age to smaller Age as when Age is 5 Cumulative Assets is 3 and when Age is 0 Cumulative Assets is 11. Which should be wrong in your scenario. To modify your issue, you can simply change ASC to DESC, then use my formula to get the Cumulative Fault Rate.

 

Cumulative Assets = 
CALCULATE(
	[Total Assets],
	FILTER(
		ALLSELECTED('Age Table'[Age]),
		ISONORAFTER('Age Table'[Age], MAX('Age Table'[Age]), DESC)
	)
)

By the way, if you want to get a cumulative sum of a measure. I would highly suggest you to use SUMX() instead of using the quick measure. For the Cumulative Assets, it can be:

 

Cumulative Assets = 
SUMX(
	FILTER(
		ALLSELECTED('Age Table'[Age]),
		'Age Table'[Age] <= MAX ( 'Age Table'[Age] )
	),
    [Total Assets]
)

1.PNG

 

Thanks,
Xi Jin.

Hi @v-xjiin-msft

glad to hear you got the file OK.

I want the cumulative asset formula to be desc. 

think of it as 'total number of assets >= age(row)'....every month the current assets move into the next age bracket higher

 

Is it possible to have the cumulative asset formula desc like it currently is, and the cumulative fault rate increasing with age (eg asc)?

 

Thanks for your help on this

 

Matt

Hi @v-xjiin-msft,

Did my last reply make sense?

I have still not been able to solve this issue and was wondering if you had any further ideas?

I appreciate your time and help with this. 

thanks,

Matt 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.