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
Zyg_D
Continued Contributor
Continued Contributor

Comparing to category average

I have the 3 first columns, and I want to get the blue one. The values are obtained by comparing grades to grade averages of each area. How to do it?

image.png

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @Zyg_D ,

 

Try this one:

 

Column =
VAR _avg = CALCULATE(AVERAGE('Table (2)'[Grade]); FILTER('Table (2)'; 'Table (2)'[Area] = EARLIER('Table (2)'[Area])))
RETURN IF('Table (2)'[Grade] < _avg; "Below Average";
IF('Table (2)'[Grade] = _avg; "Average";
"Above Average")
)
 
This column is static, if you need it dynamically you can use this link as reference:
 
 
Did I answer your question? Mark my post as a solution!
Ricardo
 


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

7 REPLIES 7
AlB
Super User
Super User

Hi @Zyg_D 

Create a new calculated column in your table:

above_below =
VAR area_avg_ =
    CALCULATE ( AVERAGE ( Table1[grade] ), ALLEXCEPT ( Table1, Table1[area] ) )
RETURN
    SWITCH (
        TRUE (),
        Table1[grade] > area_avg_, "above average",
        Table1[grade] = area_avg_, "average",
        Table1[grade] < area_avg_, "below average"
    )

Please mark the question solved when done and consider giving kudos if posts are helpful.

 Cheers 

SU18_powerbi_badge

 

 

Zyg_D
Continued Contributor
Continued Contributor


@AlB wrote:

Create a new calculated column in your table:

 

above_below =
VAR area_avg_ =
    CALCULATE ( AVERAGE ( Table1[grade] ), ALLEXCEPT ( Table1, Table1[area] ) )
RETURN
    SWITCH (
        TRUE (),
        Table1[grade] > area_avg_, "above average",
        Table1[grade] = area_avg_, "average",
        Table1[grade] < area_avg_, "below average"
    )

 

 


Although I like that you properly formatted your answer, it evaluated as error to me. 

camargos88
Community Champion
Community Champion

Hi @Zyg_D ,

 

Try this one:

 

Column =
VAR _avg = CALCULATE(AVERAGE('Table (2)'[Grade]); FILTER('Table (2)'; 'Table (2)'[Area] = EARLIER('Table (2)'[Area])))
RETURN IF('Table (2)'[Grade] < _avg; "Below Average";
IF('Table (2)'[Grade] = _avg; "Average";
"Above Average")
)
 
This column is static, if you need it dynamically you can use this link as reference:
 
 
Did I answer your question? Mark my post as a solution!
Ricardo
 


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Greg_Deckler
Super User
Super User

above/below =
VAR __grade = MAX('Table'[grade])
VAR __area = MAX('Table'[area])
VAR __average = AVERAGEX(FILTER(ALL('Table'),[area]=__area),[grade])
IF(__grade >= __average,"above average","below average")

@ 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...
Zyg_D
Continued Contributor
Continued Contributor


@Greg_Deckler wrote:
above/below =
VAR __grade = MAX('Table'[grade])
VAR __area = MAX('Table'[area])
VAR __average = AVERAGEX(FILTER(ALL('Table'),[area]=__area),[grade])
IF(__grade >= __average,"above average","below average")

Sorry, even after adding RETURN before IF it yields wrong results - always above average.

Because it is a measure and you are probably trying to use it in a column.

 

Column form:

 

above/below =
  VAR __grade = [grade]
  VAR __area = [area]
  VAR __average = AVERAGEX(FILTER('Table',[area]=__area),[grade])
RETURN
  IF(__grade >= __average,"above average","below average")

 


@ 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...
Zyg_D
Continued Contributor
Continued Contributor


@Greg_Deckler wrote:

Because it is a measure and you are probably trying to use it in a column.

 

Column form:

 

 

above/below =
  VAR __grade = [grade]
  VAR __area = [area]
  VAR __average = AVERAGEX(FILTER('Table',[area]=__area),[grade])
RETURN
  IF(__grade >= __average,"above average","below average")

 

 


Is performance-wise measure better than calculated column?

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.