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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

percent of total

Hello, can you help me?
I would like to calculate the cumulative percentage of sales of my salespeople.
The expected result would be the yellow column.
If it had a date it would be easier, but my table is just that information, name of the seller and sales.

Link excel with formula and data.

 https://we.tl/t-jfLwoutYi5

Souza_0-1594049756102.png

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

You are going to need some way to know how to accumulate. I added an index column in Power Query (Add Column menu, Index.) Just make sure your data is sorted the way you want before you add the index. You are right, a date would make this easier, but the Index works just fine. I am not aware of a way to add such an index in DAX, and adding an index is a modeling issue anyway, so that really is best done in Power Query when possible.

edhans_0-1594050866436.png

 

Cumulative Percent = 
 VAR varCurrentIndex =
    MAX( 'Table'[Index] )
VAR varGrandTotal =
    SUMX(
        ALL( 'Table' ),
        'Table'[sales]
    )
VAR varCumulativeTotal =
    SUMX(
        FILTER(
            ALL( 'Table' ),
            'Table'[Index] <= varCurrentIndex
        ),
        'Table'[sales]
    )
VAR Result =
    DIVIDE(varCumulativeTotal,varGrandTotal,0)
RETURN
    Result

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
edhans
Super User
Super User

You are going to need some way to know how to accumulate. I added an index column in Power Query (Add Column menu, Index.) Just make sure your data is sorted the way you want before you add the index. You are right, a date would make this easier, but the Index works just fine. I am not aware of a way to add such an index in DAX, and adding an index is a modeling issue anyway, so that really is best done in Power Query when possible.

edhans_0-1594050866436.png

 

Cumulative Percent = 
 VAR varCurrentIndex =
    MAX( 'Table'[Index] )
VAR varGrandTotal =
    SUMX(
        ALL( 'Table' ),
        'Table'[sales]
    )
VAR varCumulativeTotal =
    SUMX(
        FILTER(
            ALL( 'Table' ),
            'Table'[Index] <= varCurrentIndex
        ),
        'Table'[sales]
    )
VAR Result =
    DIVIDE(varCumulativeTotal,varGrandTotal,0)
RETURN
    Result

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

@edhans 

Ouw, Perfect. So it worked perfectly, thank you very much. Would it be that instead of using the index, using rank in dax would work?

Maybe, but you would have to deal with the issues of a tie, which could be handled with the DENSE vs SKIP flag in RANKX. But it will for sure make the DAX more complex and possibly slow down the model depending on how many you are doing. 4-5, or 400-500 won't matter. If you get in to the thousands or tens of thousands, you'll see using RANKX start to slow things down for your visuals if used this way.

 

And I assume you know it would always do cumulative totals from highest to lowest (or reversed) vs how the data comes in.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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