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
Anonymous
Not applicable

Highlight max and min values in a visual

Hi,

 

I tried to use conditional formatting to display the min and max values of a measure in a matrix; I did not find how to do so.

I followed this topic but it does not allow to highlight both min and max.

 

In my case, I have 4 regions and a measure containing the sales. I want to display the cells in green where sales are max for a region and in red where sales are min for a region.

 

Could you explain me how to do this?

Thanks

 

EDIT: the topic I linked allows to highlight min and max (if you create var 'min' and var 'max'). But is this method the only way to have this result?

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

Hello @Anonymous 

You can use a measure like this to feed the color to the conditional formatting.  

FormatMeasure = 
VAR MaxAmount = CALCULATE(MAXX(VALUES('Table'[Region]),[Sales Amount]),ALL('Table'[Region]))
VAR MinAmount = CALCULATE(MINX(VALUES('Table'[Region]),[Sales Amount]),ALL('Table'[Region]))
VAR LineAmonut = [Sales Amount]
RETURN 
SWITCH (
    TRUE(),
    LineAmonut = MaxAmount, "GREEN",
    LineAmonut = MinAmount, "RED"
    )    

In my example I format [Sales Amount] based on the Field value of the [FormatMeasure]:

conditionalformatminmax.jpg

This will format only the hightest and lowest out of all the regions meaning, if you welect Central, Southeast and Southwest none of them would be formatted because none of those are the highest or lowest.

If you want it to highlight the hightest and lowest out of all the visable regions it would look like so.

FormatMeasure = 
VAR SelectedRegions = ALLSELECTED('Table'[Region])
VAR MaxAmount = CALCULATE(MAXX(SelectedRegions,[Sales Amount]),SelectedRegions)
VAR MinAmount = CALCULATE(MINX(SelectedRegions,[Sales Amount]),SelectedRegions)
VAR LineAmonut = [Sales Amount]
RETURN 
SWITCH (
    TRUE(),
    LineAmonut = MaxAmount, "GREEN",
    LineAmonut = MinAmount, "RED"
    )

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

Hello @Anonymous 

You can use a measure like this to feed the color to the conditional formatting.  

FormatMeasure = 
VAR MaxAmount = CALCULATE(MAXX(VALUES('Table'[Region]),[Sales Amount]),ALL('Table'[Region]))
VAR MinAmount = CALCULATE(MINX(VALUES('Table'[Region]),[Sales Amount]),ALL('Table'[Region]))
VAR LineAmonut = [Sales Amount]
RETURN 
SWITCH (
    TRUE(),
    LineAmonut = MaxAmount, "GREEN",
    LineAmonut = MinAmount, "RED"
    )    

In my example I format [Sales Amount] based on the Field value of the [FormatMeasure]:

conditionalformatminmax.jpg

This will format only the hightest and lowest out of all the regions meaning, if you welect Central, Southeast and Southwest none of them would be formatted because none of those are the highest or lowest.

If you want it to highlight the hightest and lowest out of all the visable regions it would look like so.

FormatMeasure = 
VAR SelectedRegions = ALLSELECTED('Table'[Region])
VAR MaxAmount = CALCULATE(MAXX(SelectedRegions,[Sales Amount]),SelectedRegions)
VAR MinAmount = CALCULATE(MINX(SelectedRegions,[Sales Amount]),SelectedRegions)
VAR LineAmonut = [Sales Amount]
RETURN 
SWITCH (
    TRUE(),
    LineAmonut = MaxAmount, "GREEN",
    LineAmonut = MinAmount, "RED"
    )

Isn't this only applicable when you try to color the max or min for a "column" not a "measure"?

No, the MAXX pulls the highest amount for the measure over the defined iteration table, VALUES('Table'[Region]) in this case, and compares that to the value of the measure in the visual.

What I am saying is that in your code, the sales amount is a column. What you are trying to do here is to find the max sales amount in the region table. But what if sales amount is a measure? The value function can only take column, not measure.

VAR MaxAmount = CALCULATE(MAXX(VALUES('Table'[Region]),[Sales Amount]),ALL('Table'[Region]))

The sales amount is not a column, it is a measure.  I have attached a sample file for you to look at.

I see what you mean here. Sorry. My bad

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.