cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Sidhu
Frequent Visitor

Totals based on each row

I need to calcualte the total opportunity from average for each category, somehow the totals are not showing up, is there any way to display the totals, Here is the data and the dax I have used.

Data 

CountryLocationSpendnet
USACategory1100500
USACategory220100
UKCategory150400
UKCategory240100

DAX -

Measure -  SpendPerNet = DIVIDE(SUM('Table'[Spend]),SUM('Table'[Net]),0)*1000

Measure - OpportunityfromAverage = VAR SpendPerNetAverage = CALCULATE(AVERAGEX(VALUES('Table'[Location Category]),[SpendPerNet]),ALL('Table'[Location]))
RETURN   IF([SpendPerNet]-SpendPerNetAverage>0,('Table'[SpendPerNet]-SpendPerNetAverage)*sum('Table'[Net])/1000,0)
Sidhu_0-1664813839862.png

Opportunity Average total should sum both 18.75 and 10 and show as 28.75. I tried multiple options but nothing worked.

1 ACCEPTED SOLUTION

@Sidhu OK, I got this to work (below). I did some refactoring so check the PBIX below signature.

OpportunityfromAverageTotal = 
 VAR __Table1 = 
    ADDCOLUMNS(
        SUMMARIZE(ALL('Table'),[Location],[Category]),
        "__SpendPerNet",[SpendPerNet],
        "__SpendPerNetAverage",[SpendPerNetAverage],
        "__Measure",[OpportunityfromAverage]
    )
RETURN
    IF(ISINSCOPE('Table'[Location]),[OpportunityfromAverage],SUMX(__Table1,[__Measure]))

 


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Super User
Super User

@Sidhu This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks for the quick reply, I am getting a different result now. Is this because how I calculate average?

Sidhu_0-1664817921908.png

 

@Sidhu So the technique is to get your measure that works for your individual rows. Create a new measure like:

OpportunityfromAverageTotal =
  VAR __Table = SUMMARIZE('Table',[Location],[Category],"__Measure",[OpportunityfromAverage])
RETURN
  IF(HASONEVALUE('Table'[Country]),[OpportunityfromAverage],SUMX(__Table,[Measure]))

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  I tried that but the totals are blank

Sidhu_1-1664820190397.png

 

@Sidhu What is [Location Category], I would have expected [Location], [Category]


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Its a concatenated field of Location and category which should not have any impact, replaced it with location and category. Here is the link for the PBI file.

https://1drv.ms/u/s!AvujJeYUZlNThPRak2vASNT87nAssg?e=weT0gg 

 

@Sidhu OK, I got this to work (below). I did some refactoring so check the PBIX below signature.

OpportunityfromAverageTotal = 
 VAR __Table1 = 
    ADDCOLUMNS(
        SUMMARIZE(ALL('Table'),[Location],[Category]),
        "__SpendPerNet",[SpendPerNet],
        "__SpendPerNetAverage",[SpendPerNetAverage],
        "__Measure",[OpportunityfromAverage]
    )
RETURN
    IF(ISINSCOPE('Table'[Location]),[OpportunityfromAverage],SUMX(__Table1,[__Measure]))

 


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That worked, thank you so much

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors