Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I'm hoping you may be able to assist me in working out how to conditional format a cell in a matrix based on the previous value. In the example if its > previous value = RED
Below is the data example I would like to apply the formatting to
Plant | 11.02.2019 | 18.02.2019 | 04.03.2019 | 25.03.2019 | 01.04.2019 | 08.04.2019 | 15.04.2019 | 02.05.2019 | 06.05.2019 | 13.05.2019 | 03.06.2019 | 11.06.2019 |
1 | 11,762 | 15,451 | 6,613 | 3,258 | 5,265 | 3,161 | 2,545 | 12,335 | 12,357 | 9,652 | 5,760 | 5,706 |
2 | ||||||||||||
3 | 1,158 | 5,240 | 1,426 | 270 | 609 | 2,813 | 2,877 | 3,472 | 3,472 | 4,635 | 3,927 | 9,283 |
4 | 305,266 | 398,134 | 258,834 | 240,575 | 285,684 | 308,224 | 232,881 | 256,614 | 254,044 | 271,052 | 338,340 | 254,701 |
5 | 9,649 | 1,822 | 1,829 | 2,321 | 2,321 | 2,321 | 2,321 | 3,368 | 3,368 | 3,460 | 3,245 | 3,245 |
6 | 7,170 | 8,998 | 10,936 | 11,295 | 32,242 | 31,942 | 31,944 | 33,948 | 34,075 | 34,209 | 33,791 | 33,743 |
7 | ||||||||||||
8 | 25,639 | 27,284 | 19,407 | 19,881 | 29,681 | 11,620 | 23,285 | 30,704 | 31,932 | 36,046 | 76,772 | 89,762 |
I have tried earlier ended up with a context error (EARLIER/EARLIEST refers to an earlier row context which doesn't exist.)
previous Val = CALCULATE ( MAX (DATA[Value] ), FILTER ( ALL ( DATA ), DATA[DateKey] = EARLIER (DATA[DateKey] ) )
Solved! Go to Solution.
@David01 ,
Suppose in your table there's same date value in column [DateKey], create a calculate column to give index in each plant based on [DateKey].
DateKey Index Ascend = COUNTROWS ( FILTER ( DATA, DATA[Plant] = EARLIER ( DATA[Plant] ) && DATA[Index] <= EARLIER ( DATA[Index] ) && DATA[DateKey] <= EARLIER ( DATA[DateKey] ) ) )
Then create another color column named [If Red] like below.
If Red = VAR Current_Index = DATA[DateKey Index Ascend] VAR Previous_Index = Current_Index - 1 VAR Current_Value = CALCULATE(MAX(DATA[Value]), FILTER(DATA, DATA[DateKey Index Ascend] = Current_Index)) VAR Previous_Value = CALCULATE(MAX(DATA[Value]), FILTER(DATA, DATA[DateKey Index Ascend] = Previous_Index)) RETURN IF(Current_Index <> 1 && Current_Value > Previous_Value, "Red", BLANK())
Then you know which value should be colored in red.
Finally create a matrix visual, in advanced conditional formatting pane, select "First Value".
I haven't input all of your data, so the result will be like below.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@David01 ,
Suppose in your table there's same date value in column [DateKey], create a calculate column to give index in each plant based on [DateKey].
DateKey Index Ascend = COUNTROWS ( FILTER ( DATA, DATA[Plant] = EARLIER ( DATA[Plant] ) && DATA[Index] <= EARLIER ( DATA[Index] ) && DATA[DateKey] <= EARLIER ( DATA[DateKey] ) ) )
Then create another color column named [If Red] like below.
If Red = VAR Current_Index = DATA[DateKey Index Ascend] VAR Previous_Index = Current_Index - 1 VAR Current_Value = CALCULATE(MAX(DATA[Value]), FILTER(DATA, DATA[DateKey Index Ascend] = Current_Index)) VAR Previous_Value = CALCULATE(MAX(DATA[Value]), FILTER(DATA, DATA[DateKey Index Ascend] = Previous_Index)) RETURN IF(Current_Index <> 1 && Current_Value > Previous_Value, "Red", BLANK())
Then you know which value should be colored in red.
Finally create a matrix visual, in advanced conditional formatting pane, select "First Value".
I haven't input all of your data, so the result will be like below.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
What would be the dax if you wanted to label each of the rows red if its greater then the previous DateKey index? rather then just looking at the most current, hope that makes sense!
Thanks for the reply @v-yuta-msft
I created the indexs in TSQL then applied the dax as you had written but had to make one change being I had to add a second filter. (Changed DAX below)
This gave me what I needed thanks.
Figured out why I got the error when using earlier before I was trying to use it in a measure. I wanted the report to be more dynamic in being abled to be filtered dynamically.
The underlying data not provided had another level being product type. So for each plant & period there were many products.
I had to remove that level to get the inital report to work.
If Red = VAR Current_Index = DATA[DateKey Index Ascend] VAR Previous_Index = Current_Index - 1 var plant_key = DATA[PlantKey] VAR Current_Value = CALCULATE(MAX(DATA[Value]), FILTER(DATA, DATA[DateKey Index Ascend] = Current_Index),FILTER(DATA, DATA[PlantKey] = plant_key)) VAR Previous_Value = CALCULATE(MAX(DATA[Value]), FILTER(DATA, DATA[DateKey Index Ascend] = Previous_Index),FILTER(DATA, DATA[PlantKey] = plant_key)) RETURN IF(Current_Index <> 1 && Current_Value > Previous_Value, "Red", BLANK())
User | Count |
---|---|
141 | |
113 | |
104 | |
78 | |
64 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |