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.
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?
Solved! Go to Solution.
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" )
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" )
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]))
I see what you mean here. Sorry. My bad
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
103 | |
77 | |
66 | |
63 |
User | Count |
---|---|
142 | |
105 | |
102 | |
81 | |
68 |