Keeping conditional formatting consistent when filtering

34 Views Asked by At

The users of my report are getting confused, because when using slicers the visual conditional formatting is changing.

I have a table visual with the following conditional formatting:

formatting

This CF is applied to this visual (edit: pls keep in mind that it bugged and on the screenshot lowest and highest colors are reverted - lowest should be red and highest - green):

all regions

When I select Mexico (rank 1), I want to see it colored in green (as it is when no selections are made). In fact, it is showing up in red:

mexico selected

I understand that it is showing wrong color because we only have 1 value, because Mexico value is minimum and maximum in that case (although I can't quite grasp why it shows exactly red).

The goal is that this color stays always the same, based on all subgroups, regardless of the selections in the slicer. Something like how the ranking number stays the same, no matter how many subgroups I have selected - Canada Rank 2, China Rank 5: 

2 selections

2

There are 2 best solutions below

0
ttruhcheva On BEST ANSWER

I found an acceptable workaround for this. I used a website to generate gradient from green to red. The site is this. It gave me the opportunity to enter a step number (it will get from green to red in a certain number of steps).

I then created the following measure:

Ranking% Formatting = 
VAR maxvalue =
    MAXX ( ALL ( Subgrp ), [ranking%] ) // defining max value for current selection
VAR step = maxvalue / 6 // calculating a step which will be used for returning colors (random number, in my case I match number of subgroups)
VAR Result =
    SWITCH (
        TRUE (),
        [ranking%] <= maxvalue
            && [ranking%] > maxvalue - step, "#6c8c26",
        [ranking%] <= maxvalue - step
            && [ranking%] > maxvalue - ( step * 2 ), "#8d9120",
        [ranking%] <= maxvalue - ( step * 2 )
            && [ranking%] > maxvalue - ( step * 3 ), "#977a1a",
        [ranking%] <= maxvalue - ( step * 3 )
            && [ranking%] > maxvalue - ( step * 4 ), "#9c5714",
        [ranking%] <= maxvalue - ( step * 4 )
            && [ranking%] > maxvalue - ( step * 5 ), "#a12f0e",
        [ranking%] <= maxvalue - ( step * 5 )
            && [ranking%] >= 0, "#a60810"
    ) // defining brackets, and a color for each bracket which is green flowing to red, basically I am covering all the values from the max to the min - min is 0, but it can be the minimum of all values, or else
RETURN
    result

This code provides a color from red to green for each value, based on these brackets. I decided for 6, because that is the number of subgroups that I have in my data, but the number of bracket can be more or less. And this is the final result. The gradient:

enter image description here

Conditional formatting is kept, because there is already a predefined color:

enter image description here

Probably a downside to this approach is that I could not find a site that allows adding also a middle color to this path, but this works fine.

0
davidebacci On

The problem you have is that the gradient values are evaluated over the rows which exist in the table. If you only have two rows, then the min and max will span those two rows and everything will be recoloured. You only have two options to solve this.

First is use static values like this:

enter image description here

enter image description here

The other option is to compute your gradient yourself using the field value option in the conditional formatting box. There is DAX out there to compute this gradient for you and return the desired colour but it is probably overkill if you know in advance how many data points you have.

enter image description here