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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors