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
trevordunham
Helper III
Helper III

Dynamic measure to calculate impacts of a column

I want to create a measure that shows the impacts of a category column (the change in the overall score measure when the specific category is removed)

 

I want to create a table like this:

 

CategoryScoreImpactCount
a

30

-1030
b40-845
c45351
d50410
Total400

136

 

The impact column in this example is not correct just for example.

 

I tried to create this with the following fields:

 

Total Score = AVERAGE('Table'[Score])

Impact of Category = CALCULATE(AVERAGE('Table'[Score]),ALL(Table[Category])<>"Selected Category")
Impact Score = [Total Score] - [Impact of Category]
 
I know ALL(Table[Category])<>"Selected Category" is the issue with my code. What is the correct DAX to instead of <> "Selected Category", instead return where it is not equal to each category in the table dynamically? 
 
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @trevordunham ,

 

Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:  

The argument to the ALL function must be either a reference to a base table or a reference to a base column. You cannot use table expressions or column expressions with the ALL function.

Refer to:

ALL function (DAX) - DAX | Microsoft Learn

You can using the following measure

Impact of Category =
var _select=SELECTEDVALUE('Table'[Category])
return
CALCULATE(
    AVERAGE('Table'[Score]),FILTER(ALL('Table'),'Table'[Category]<>_select))

vyangliumsft_0-1712560846447.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Hi  @trevordunham ,

 

Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:  

The argument to the ALL function must be either a reference to a base table or a reference to a base column. You cannot use table expressions or column expressions with the ALL function.

Refer to:

ALL function (DAX) - DAX | Microsoft Learn

You can using the following measure

Impact of Category =
var _select=SELECTEDVALUE('Table'[Category])
return
CALCULATE(
    AVERAGE('Table'[Score]),FILTER(ALL('Table'),'Table'[Category]<>_select))

vyangliumsft_0-1712560846447.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@trevordunham 

Perhaps:

Impact of Category = 
  VAR __Category = MAX('Table'[Category]
  VAR __Table = FILTER( ALL( 'Table' ), [Category] <> __Category )
  VAR __Result = AVERAGEX( __Table, [Score] )
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...

@Greg_Deckler 

 

That seems off for some reason. My numbers are not adding up correctly.

@trevordunham Well, I would think that you would want the overall average which would be:

Total Score = AVERAGEX(ALL('Table'), [Score])

 

You may also be running into a measure totals issue. First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

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

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8


@ 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.