Forum Discussion
Anonymous
2 years agoNot applicable
Conditional Formatting Matrix
Hello Power BI Community, I am trying to create a conditional format on a matrix. The conditional format I envision will be applied on a row-by-row level. I am pretty close. I hope you can he...
- 2 years ago
Hi Anonymous
- You should use ALLSELECTED () with no arguments if you want the Range to be based on all values in the visual. This will ensure that the same number receives the same format.
- You need to add a branch to test whether Total Students > 5 & Performance Level = "Did Not Meet", and return the required "red" colour in that case.
I have attached an edited version of the PBIX.
There are two CF measures I tried:
- CF: The only change is to force Total Students > 5 & Did Not Meet to "red".
- CF v2: Same as CF, but the range is based only on the values excluding Total Students > 5 & Did Not Meet.
Here are the measures:
CF = VAR TotalStudents = [Total Students] VAR PerformanceLevel = SELECTEDVALUE ( 'Test and Intervention Hours'[Performance Level] ) VAR DidNotMeetgreaterThan5 = AND ( PerformanceLevel = "Did Not Meet", TotalStudents > 5 ) VAR OverrideColour = "red" -- adjust as needed VAR Color = IF ( DidNotMeetgreaterThan5, -- If Did Not Meet & Total Students > 5 then use OverrideColour OverrideColour, -- Otherwise use normal rule VAR SummaryTable = CALCULATETABLE ( ADDCOLUMNS ( SUMMARIZE ( 'Test and Intervention Hours', Campus[Intervention Teacher Last Name], 'Test and Intervention Hours'[Performance Level] ), "Students", [Total Students] ), ALLSELECTED () ) VAR MaxValue = MAXX ( SummaryTable, [Students] ) VAR MinValue = MINX ( SummaryTable, [Students] ) VAR Range = MaxValue - MinValue VAR Shade = ROUND ( DIVIDE ( TotalStudents - MinValue, Range ) * 120, 0 ) RETURN "hsla(" & Shade & ", " & "100%" & "," & "90%" & "," & 1 & ")" ) RETURN ColorCF v2 = VAR TotalStudents = [Total Students] VAR PerformanceLevel = SELECTEDVALUE ( 'Test and Intervention Hours'[Performance Level] ) VAR DidNotMeetgreaterThan5 = AND ( PerformanceLevel = "Did Not Meet", TotalStudents > 5 ) VAR OverrideColour = "red" -- adjust as needed VAR Color = IF ( DidNotMeetgreaterThan5, -- If Did Not Meet & Total Students > 5 then use OverrideColour OverrideColour, -- Otherwise use normal rule VAR SummaryTable = FILTER ( CALCULATETABLE ( ADDCOLUMNS ( SUMMARIZE ( 'Test and Intervention Hours', Campus[Intervention Teacher Last Name], 'Test and Intervention Hours'[Performance Level] ), "Students", [Total Students] ), ALLSELECTED () ), NOT AND ( 'Test and Intervention Hours'[Performance Level] = "Did Not Meet", [Students] > 5 ) ) VAR MaxValue = MAXX ( SummaryTable, [Students] ) VAR MinValue = MINX ( SummaryTable, [Students] ) VAR Range = MaxValue - MinValue VAR Shade = ROUND ( DIVIDE ( TotalStudents - MinValue, Range ) * 120, 0 ) RETURN "hsla(" & Shade & ", " & "100%" & "," & "90%" & "," & 1 & ")" ) RETURN Color
OwenAuger
2 years agoSuper User
Hi Anonymous
- You should use ALLSELECTED () with no arguments if you want the Range to be based on all values in the visual. This will ensure that the same number receives the same format.
- You need to add a branch to test whether Total Students > 5 & Performance Level = "Did Not Meet", and return the required "red" colour in that case.
I have attached an edited version of the PBIX.
There are two CF measures I tried:
- CF: The only change is to force Total Students > 5 & Did Not Meet to "red".
- CF v2: Same as CF, but the range is based only on the values excluding Total Students > 5 & Did Not Meet.
Here are the measures:
CF =
VAR TotalStudents =
[Total Students]
VAR PerformanceLevel =
SELECTEDVALUE ( 'Test and Intervention Hours'[Performance Level] )
VAR DidNotMeetgreaterThan5 =
AND (
PerformanceLevel = "Did Not Meet",
TotalStudents > 5
)
VAR OverrideColour = "red" -- adjust as needed
VAR Color =
IF (
DidNotMeetgreaterThan5,
-- If Did Not Meet & Total Students > 5 then use OverrideColour
OverrideColour,
-- Otherwise use normal rule
VAR SummaryTable =
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE (
'Test and Intervention Hours',
Campus[Intervention Teacher Last Name],
'Test and Intervention Hours'[Performance Level]
),
"Students", [Total Students]
),
ALLSELECTED ()
)
VAR MaxValue = MAXX ( SummaryTable, [Students] )
VAR MinValue = MINX ( SummaryTable, [Students] )
VAR Range = MaxValue - MinValue
VAR Shade =
ROUND (
DIVIDE ( TotalStudents - MinValue, Range ) * 120,
0
)
RETURN
"hsla(" & Shade & ", " & "100%" & "," & "90%" & "," & 1
& ")"
)
RETURN
ColorCF v2 =
VAR TotalStudents =
[Total Students]
VAR PerformanceLevel =
SELECTEDVALUE ( 'Test and Intervention Hours'[Performance Level] )
VAR DidNotMeetgreaterThan5 =
AND (
PerformanceLevel = "Did Not Meet",
TotalStudents > 5
)
VAR OverrideColour = "red" -- adjust as needed
VAR Color =
IF (
DidNotMeetgreaterThan5,
-- If Did Not Meet & Total Students > 5 then use OverrideColour
OverrideColour,
-- Otherwise use normal rule
VAR SummaryTable =
FILTER (
CALCULATETABLE (
ADDCOLUMNS (
SUMMARIZE (
'Test and Intervention Hours',
Campus[Intervention Teacher Last Name],
'Test and Intervention Hours'[Performance Level]
),
"Students", [Total Students]
),
ALLSELECTED ()
),
NOT AND (
'Test and Intervention Hours'[Performance Level] = "Did Not Meet",
[Students] > 5
)
)
VAR MaxValue = MAXX ( SummaryTable, [Students] )
VAR MinValue = MINX ( SummaryTable, [Students] )
VAR Range = MaxValue - MinValue
VAR Shade =
ROUND (
DIVIDE ( TotalStudents - MinValue, Range ) * 120,
0
)
RETURN
"hsla(" & Shade & ", " & "100%" & "," & "90%" & "," & 1
& ")"
)
RETURN
Color
- Anonymous2 years agoNot applicable