Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

Conditional Formatting Matrix Table by Row by Cell

Our customer asked for a daily scorecard view of a dozen targets. Each row represents a unique target.  The screenshot shows the target and the conditional formatting applied.  The ID and description columns are not shown.  This solution is for conditional formatting of a matrix table by row, by cell. 

Scorecard.JPG

A SQL Server table was created to store data from the daily batch cycle (INSERT ... SELECT COUNT(1) FROM... statements).

CREATE TABLE dbo.SCORECARD(
SC_DAY DATE,
SC_GOAL_ID INT,
SC_ACTUAL DECIMAL(8,2))

 

A table was was created in Power BI for ID (1), Description (Widget Tons), Target value (<5000t) for the first three columns of the Matrix table.  This was then joined to the SCORECARD table on SC_GOAL_ID and ID.

 

DAX was used to hardcode the logic to assign 1, 2 or 3 for low, middle, high (Green, Yellow, Red).

_Format = VAR CondFormat = SELECTEDVALUE('BH_SCORECARD'[SC_GOAL_ID]) RETURN
SWITCH(TRUE(),
CondFormat = 1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 5000,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 10000,2,3)),
CondFormat = 2,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 200,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 300,2,3)),
CondFormat = 3,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 200,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 300,2,3)),
CondFormat = 4,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 5000,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 10000,2,3)),
CondFormat = 5,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 25,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 50,2,3)),
CondFormat = 6,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 20,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 40,2,3)),
CondFormat = 7,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 20,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 40,2,3)),
CondFormat = 8,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 10,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 20,2,3)),
CondFormat = 9,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 20,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 40,2,3)),
CondFormat = 10,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 20,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 40,2,3)),
CondFormat = 11,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 10,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 20,2,3)),
CondFormat = 12,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 500,1,If(SUM('BH_SCORECARD'[SC_ACTUAL]) < 1000,2,3))
)

 

The SC_ACTUAL is placed in the Values card for the Matrix.  Conditional formatting, background is selected.  Format by Rules Based on the DAX formula, _Format.  Add an entry for each number 1, 2 & 3 and assign a color.

Scorecard2.JPG

Finally, use the Icon "Expand all down one level in the heirarchy" to drill into the report to see the finished matrix table. 

The user also wanted to see a view of the last day of the week.  Added toggle images and actions and filter to show Saturday only view.

 

HTH, Smitty

1 REPLY 1
Anonymous
Not applicable

HI @Anonymous ,

AFAIK, current power bi not contains row/column index. If you want to conditional formatting row/cell color, you need to add condition to check current row contents and compare with if statement conditions.

BTW,  I also try to transform your formula to make it dynamic based on current item and result color string to do color formatting.

_Format =
VAR selected =
    SELECTEDVALUE ( 'BH_SCORECARD'[SC_GOAL_ID] )
VAR _multi =
    IF (
        selected IN { 1, 4 },
        5000,
        IF (
            selected IN { 2, 3 },
            100,
            IF (
                selected IN { 6, 7, 9, 10, 11 },
                20,
                IF ( selected IN { 8, 11 }, 10, IF ( selected = 5, 25 ) )
            )
        )
    )
VAR _offset =
    IF ( selected IN { 2, 3 }, 100, 0 )
RETURN
    IF (
        SUM ( 'BH_SCORECARD'[SC_ACTUAL] ) < 1 * _multi + _offset,
        "Green",
        IF ( SUM ( 'BH_SCORECARD'[SC_ACTUAL] ) < 2 * _multi + _offset, "Yellow", "Red" )
    )

Conditional formatting in tables

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.