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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ylin88_waters
Helper I
Helper I

A Measure to Calculate the Cumulative Sum of Another Measure, with Filter on Measure

Hi

What’s the DAX code to create a measure that calculates the cumulative sum of another measure?

 

My data is something like following:

Customer

Sales

Rank
(measure)

% of Total
(measure)

 Cumulative %
(new measure)

A

1000

1

33.3%

33.3%

B

800

2

26.7%

60.0%

C

500

3

16.7%

76.7%

D

400

4

13.3%

90.0%

E

300

5

10.0%

100.0%

 

Both “Rank” and “% of Total” are measures. Now I need to create another measure “Cumulative %” to sum up on the measure “% of total”.

 

Many examples I found are for the calculation of cumulative sum on columns, not measures, or the filter is on the column values. but here it seems I need to filter on a measure (Rank). How do you get that Rank # into your DAX code and then sum up on “% of Total”?

 

Thanks!

 

YL

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @ylin88_waters ,

 

Check the formula.

Measure = SUMX(FILTER(ALLSELECTED('Table'),[_rank]<=MAXX('Table',[_rank])),'Table'[_% of Total])

1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @ylin88_waters ,

 

Check the formula.

Measure = SUMX(FILTER(ALLSELECTED('Table'),[_rank]<=MAXX('Table',[_rank])),'Table'[_% of Total])

1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
VahidDM
Super User
Super User

Hi @ylin88_waters 

 

Try this:

Cumulative % = 
Var _R = [Rank]
Var _A = SUMMARIZE(all('Table'),'Table'[Customer],'Table'[Sales],"Rank",[Rank])
Var _B = filter(_A,[Rank]<=_R)
Var _C = SUMX(_B,[Sales])
return
_C/CALCULATE(sum('Table'[Sales]),all('Table'))

 

output:

VahidDM_0-1644529750184.png

 

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

parry2k
Super User
Super User

@ylin88_waters try something like this:

 

**bleep** Sum = 
VAR __rank = [Rank Measure]
RETURN SUMX ( FILTER( ALL ( 'Table' ), [Rank Measure] <= __rank ), [% Total] )

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi VahidDM & parry2k:

 

Thanks a lot for your help.

I tried both of your sample codes, but they didn't work. It seems the Dax didn't really capture the Rank (a measure) of current row.  It actually calculated the sum of all rows. It seems I can't upload my testing file here(using 1000 rows of dummy data), so I just put an image of the result table.

 

ylin88_waters_0-1644591254854.png

Measures:
Sales $ = SUM('Sales_test'[Sales])
====================
Rank =
RANKX( ALLSELECTED(Sales_test[CustomerID]),'Sales_test'[Sales $])
=================
% of Total Orders =
DIVIDE( [Sales $],
CALCULATE( [Sales $],
ALL('Sales_test'[CustomerID])
))
===================
Cumulative % 1 =
VAR myrank = [Rank]
RETURN SUMX ( FILTER( ALL ( 'Sales_test' ), [Rank] <= myrank ), [% of Total Orders] )
 ====================
Cumulative Sales 1 =
VAR __rank = [Rank]
RETURN SUMX ( FILTER( ALL ( 'Sales_test' ), [Rank] <= __rank ), [Sales $] )
==============
Cumulative % 2 =
Var _R = [Rank]
Var _A = SUMMARIZE(all('Sales_test'),'Sales_test'[CustomerID],[Sales],"Rank",[Rank])
Var _B = filter(_A,[Rank]<=_R)
Var _C = SUMX(_B,[Sales $])
return
_C/CALCULATE(sum([Sales]),all('Sales_test'))

 =====================

If you see anything I need to change to make it work, le tme know. Thanks again.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.