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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Calculating the number of rows until it reaches 80, Sorted descending

Hi Team,

 

I've following dataset:

CustomerValueSales
A1113.61%4200
A1212.97%4000
A1311.99%3700
A1411.67%3600
A159.08%2800
A88.10%2500
A107.46%2300
A76.48%2000
A96.48%2000
A64.86%1500
A53.24%1000
A31.62%500
A21.30%400
A10.65%200
A40.49%150

 

I want to create a measure that gives me count of rows till it reaches 80. 

I tried following dax:

 

Count of Products Making 80% of Margin =
COUNTROWS(FILTER(Sales,Sales[Value]<=80))
But it gives me answer 15, since it calculates all those rows which sums <=80.
I want to sort the percentage column(value) in descending order and count the rows until my sum is <=80.
In above case it should give me Count = 5.
I need a measure since I want to use it in a card.
 
Thanks in advance!
1 ACCEPTED SOLUTION
calerof
Impactful Individual
Impactful Individual

Hello @valentina14 ,

You need %cummulatvie sales, not the only one. You can follow the large @AlbertoFerrari to calculate the ABC Classification in DAX Patterns for products and adapt it to your needs.

You must add 4 columns:

1) Customer Sales = Valentina[Sales]

2) Cummulative Sales = 
VAR CurrentCustomerSales = Valentina[Customer Sales]
VAR BetterCustomers =
    FILTER (
        Valentina,
        Valentina[Customer Sales] >= CurrentCustomerSales
    )
VAR Result =
    SUMX (
        BetterCustomers,
        Valentina[Customer Sales]
    )
RETURN
    Result

3) Cummulative Pct = 
DIVIDE (
    Valentina[Cumulated Sales],
    SUM ( Valentina[Customer Sales] )
)

4) Pareto Class = 
SWITCH (
    TRUE,
    Valentina[Cummulative Pct] <= 0.8, "80% Pareto",
    Valentina[Cummulative Pct] <= 1, "20% Rest"
)

And you understand this:

Vale.png

I hope it helps.

Bless you

Fernando

P.S. If it helped, please consider liking the post and mark it as an answer!

View solution in original post

4 REPLIES 4
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

I suggest create two calculated column one for rank and the other one for the cumulative value:

 

Rank = RANKX('Table','Table'[Value],,DESC) 
Cvalue = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Rank]<=EARLIER('Table'[Rank]))) 

 

Capture1.PNG

 

Then you can create a measure for card visual  to gives me count of rows till  cumulative value reaches 80%.

 

Measure = CALCULATE(MAX('Table'[Rank]),FILTER('Table','Table'[Cvalue]<=0.8))

 

Capture2.PNG

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EambX0CGNMlFq-kc-72FNzIBEBkUDhTNJJgiT__a5m8IAw?e=hln0yM

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

I've spent most of my day trawling forums, YouTube and blogs for this answer. THANK YOU. I know calculated columns aren't advisable but this gets the job done way quicker than attempting a similar output in a measure. My visuals wouldn't even load due to the volume of data I'm working with but at least my visuals render once this is calculated per row and stamped on the table. Thanks again!

Ashish_Mathur
Super User
Super User

Hi,

The answer should be 7.  You may download my PBI file from here.

Hope this helps.

Customers that make up 80% of sales.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
calerof
Impactful Individual
Impactful Individual

Hello @valentina14 ,

You need %cummulatvie sales, not the only one. You can follow the large @AlbertoFerrari to calculate the ABC Classification in DAX Patterns for products and adapt it to your needs.

You must add 4 columns:

1) Customer Sales = Valentina[Sales]

2) Cummulative Sales = 
VAR CurrentCustomerSales = Valentina[Customer Sales]
VAR BetterCustomers =
    FILTER (
        Valentina,
        Valentina[Customer Sales] >= CurrentCustomerSales
    )
VAR Result =
    SUMX (
        BetterCustomers,
        Valentina[Customer Sales]
    )
RETURN
    Result

3) Cummulative Pct = 
DIVIDE (
    Valentina[Cumulated Sales],
    SUM ( Valentina[Customer Sales] )
)

4) Pareto Class = 
SWITCH (
    TRUE,
    Valentina[Cummulative Pct] <= 0.8, "80% Pareto",
    Valentina[Cummulative Pct] <= 1, "20% Rest"
)

And you understand this:

Vale.png

I hope it helps.

Bless you

Fernando

P.S. If it helped, please consider liking the post and mark it as an answer!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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