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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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