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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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]))

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

@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



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!:
DAX For Humans

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]))


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!:
DAX For Humans

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]



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!:
DAX For Humans

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]))

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That worked, thank you so much

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.