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

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

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

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

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

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That worked, thank you so much

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.

Top Solution Authors