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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
DK_analyst
Frequent Visitor

Percent of grand total of distinct values in data with row duplication

Good morning, Power BI gurus. I humbly present the problem that has stumped me for the last 24 hours of screen time (I wish I were kidding):

I am working with sales data that has a significant amount of duplication in it. The duplication was done deliberately, as it was neccessary for another calculation I had to make.

The tasks are to find both the sum of the distinct product's sale priceover a given time period, and the percent of the overall grand total each distinct product's sale price is. The data also has a date component to it, as the final report will need to be sliced by time period.

Here is some example data:

YearProductSale Price
2022A100
2022A100
2022A100
2022A100
2022A100
2022B150
2022B150
2022C50
2022C50
2022C50
2022C50
2022D200
2022D200
2022D200
2022D200
2022D200


The final report with the above aggregations is supposed to look like this:

YearProductSale PricePercent
2022A10020%
2022B15030%
2022C5010%
2022D20040%
    
 Total500100%


I was able to create a measure that accurately calculates the sale price and the distinct sum correctly using SUMX and Calculate (I'm still learning about context transitions, and I know that's what's happening here):

SUMX(
     VALUES('Data'[Product]),
     CALCULATE(
          MAX('Data'[Sale Price]),
     )
)


However, I am unable to figure out how to accurately calculate the percent column. Intuitively it's simple: just take the sale price of each displayed value and divide it by the displayed grand total. However I cannot figure it out.

Any help or guidance here would be much appreciated.

 

1 ACCEPTED SOLUTION
Padycosmos
Solution Sage
Solution Sage

3 REPLIES 3
Padycosmos
Solution Sage
Solution Sage

This video covers your requirement :

https://www.youtube.com/watch?v=3IHsIngGdjU

DK_analyst
Frequent Visitor

@Greg_Deckler Thank you very much for your reply. I tested the solution out, but unfortionatly that it didn't work. Your code returns 100% for each product, and after I debugging I discovered that the "__Total" variable is actually recalculating the exact value my original code did for the sale price, and 100/100 will always be %100.

Any other ideas? 😅

Greg_Deckler
Super User
Super User

@DK_analyst Here is one way:

Price Percent = 
    VAR __Row = AVERAGE(Data[Sale Price])
    VAR __Table = SUMMARIZE(ALL('Data'),[Year],[Product],"__Avg",AVERAGE(Data[Sale Price]))
    VAR __Total = SUMX(__Table,[__Avg])
    VAR __Result = 
        IF(
            ISINSCOPE('Data'[Product]),
            DIVIDE(__Row, __Total),
            DIVIDE(__Total, __Total)
        )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors