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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply

Conditional Formatting based on result of a measure

Hello and thank you for any help you can provide.

 

I have two rows of card, one aggragated to one level (region) above the other (teams) and would like the font color to change when the result of the teams values is greater than the average of the region value.  I am getting lost in the sauce writting the dax for it because I have very little experience with calculate (I assume that's what I need to change the aggragation level via filters).

 

Region.jpg

 

team.jpg

 

This is the current set up I have (I cut around some sensitive info) the top is the regions stats, the bottom is the team stats.  I would like some of the callout values to highlight green when above/below the region value depending on which category it is.  These are both aggragations of values that go down another level (pods) so I can't just hardcode the values.

 

How would I write a dax measure that allows me to accomplish this?  I was thinking something like:

=if(calculate(<average of measure, filtered to team)>calculate(average of measure, filtered up to region), "Green") (I have hex codes for the actual color)

 

Please let me know what I have left out, I don't feel I have explained it very well but am unsure how else to word it.

 

Example data: Call Scores would be an average, CTCs would be a sum

MonthRegionTeamPodCall ScoreCTCs
JanuaryJohn SmithPistonsHot Pot0.967523
JanuaryJohn SmithLakersSushi0.968213
JanuaryJane DoeBearsBagels0.986515
JanuaryJane DoeBearsDonuts0.954321
JanuaryJohn SmithLakersNigiri0.964219
1 ACCEPTED SOLUTION

@LYorkToenniges,

 

Since there's a Team slicer, you can adjust the vTeamAmount variable to simply be the underlying average measure. The vRegionAmount variable can be adusted to use ALL which removes all filter context, keeping only the Region.

 

Conditional Formatting Measure =
VAR vTeamAmount = [Average Call Score]
VAR vRegionAmount =
    CALCULATE ( [Average Call Score], ALL ( 'Table' ), VALUES ( 'Table'[Region] ) )
VAR vResult =
    IF ( vTeamAmount > vRegionAmount, "Green", "Other Color" )
RETURN
    vResult




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
DataInsights
Super User
Super User

@LYorkToenniges,

 

You could try measures like these. The function ALLSELECTED clears the filter context from within the visual, keeping external filters such as slicers. The VALUES function captures the filter context for the specified column.

 

Average Call Score = AVERAGE ( 'Table'[Call Score] )
Conditional Formatting Measure =
VAR vTeamAmount =
    CALCULATE ( [Average Call Score], ALLSELECTED (), VALUES ( 'Table'[Team] ) )
VAR vRegionAmount =
    CALCULATE ( [Average Call Score], ALLSELECTED (), VALUES ( 'Table'[Region] ) )
VAR vResult =
    IF ( vTeamAmount > vRegionAmount, "Green", "Other Color" )
RETURN
    vResult

 





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

Proud to be a Super User!




I think this would work if I didn't have a slicer for team working on the page.  When I try the individual pieces they result in the same value as the team card has, not the team and the region.

@LYorkToenniges,

 

Since there's a Team slicer, you can adjust the vTeamAmount variable to simply be the underlying average measure. The vRegionAmount variable can be adusted to use ALL which removes all filter context, keeping only the Region.

 

Conditional Formatting Measure =
VAR vTeamAmount = [Average Call Score]
VAR vRegionAmount =
    CALCULATE ( [Average Call Score], ALL ( 'Table' ), VALUES ( 'Table'[Region] ) )
VAR vResult =
    IF ( vTeamAmount > vRegionAmount, "Green", "Other Color" )
RETURN
    vResult




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

Proud to be a Super User!




Thank you very much!  It worked perfectly.  I really need to find some good tutorials (and free time) to wrap my head around filter context issues.  I really struggle with it.

@LYorkToenniges,

 

Glad to hear that works. Filter context can be challenging. The book below is the best resource I've found on the topic:

 

https://www.sqlbi.com/books/the-definitive-guide-to-dax/ 





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

Proud to be a Super User!




Thank you!  Looks like I have some reading to do!

Thank you so much, I will give this a whirl next chance I get and let you know how it goes!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.