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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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