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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors