Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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?

  • 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]:

    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"
        )

6 Replies

  • 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]:

    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"
        )
    • abbynie08's avatar
      abbynie08
      Icon for Microsoft Employee rankMicrosoft Employee

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

      • jdbuchanan71's avatar
        jdbuchanan71
        Icon for Super User rankSuper User

        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.