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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
mojekk
Frequent Visitor

Conditional Formatting for Matrix Based on Movement

I have a sample data as below:

ACCOUNT IDPREVIOUS RATINGCURRENT RATINGOUTSTANDING BALANCERATING MOVEMENT
TXPOJ11$ 291.31REMAIN
YYECT911$ 540.40DOWNGRADE
UMTMH512$ 978.56DOWNGRADE
UFVLV46$ 570.59DOWNGRADE
XACKM84$ 549.44UPGRADE
YXLHA911$ 909.79DOWNGRADE
JECLT45$ 845.84DOWNGRADE
LOFBN13$ 68.00DOWNGRADE
VKQDO25$ 140.86DOWNGRADE
GODYZ67$ 363.34DOWNGRADE
YRCHL311$ 667.65DOWNGRADE
NVQOZ121$ 165.71UPGRADE
UXHMB27$ 123.50DOWNGRADE
UXYJZ66$ 881.34REMAIN
OBTFU32$ 17.52UPGRADE
MKSYX111$ 815.95UPGRADE
OVYYH99$ 254.64REMAIN
ZLGVP36$ 641.07DOWNGRADE
BEWNR510$ 935.71DOWNGRADE
UOXJT55$ 167.13REMAIN
IXNUP116$ 102.83UPGRADE
CPFTS87$ 631.63UPGRADE
ZDMGZ102$ 339.78UPGRADE
BJBNZ911$ 291.88DOWNGRADE
CEUOW95$ 222.41UPGRADE
QBMBK28$ 764.01DOWNGRADE
FQHWC24$ 789.33DOWNGRADE
HKUGC610$ 279.36DOWNGRADE
LVCTG81$ 941.53UPGRADE
BIRCZ78$ 884.07DOWNGRADE

 

And I have created a matrix in Power BI and my end goal is to have it coloured based on its Rating Movement. Below is the matrix that I have created in Excel:

mojekk_1-1736362331185.png

 

 

The Red is Downgrade, Green Upgrade and Grey is Remain. I have created DAX query to be used in conditional formatting like SWITCH (TRUE()) and create a table so that blank cell filled with zero. But nothing works. Appreciate if any expert can assist me on resolving this issue. 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from speedramps, please allow me to provide another insight.
Hi @mojekk ,

 

Please refer to the following steps.

 

Create two rating tables, derived from the PREVIOUS RATING and CURRENT RATING fields, and establish a relationships.Use the fields from these two tables as the rows and columns of the matrix.

Previous rating = GENERATESERIES(MIN('Table'[PREVIOUS RATING]),MAX('Table'[PREVIOUS RATING]),1)
Current rating = GENERATESERIES(MIN('Table'[CURRENT RATING]),MAX('Table'[CURRENT RATING]),1)

vdengllimsft_0-1736400217990.png

 

Creates a measure to display the OUTSTANDING BALANCE and uses this measure as the value field of the matrix.

Sum of Outstanding Balance = 
IF (
    MAX ( 'Table'[RATING MOVEMENT] ) <> BLANK (),
    SUM ( 'Table'[OUTSTANDING BALANCE] ),
    0
)

 
Creates measures for the background color and font color to be used for the matrix values.

BackgroundColor = 
VAR rating_movement = MAX('Table'[RATING MOVEMENT])
VAR previous_rating = MAX('Previous rating'[value])
VAR current_rating = MAX('Current rating'[value])
VAR _result = SWITCH(rating_movement,
        "UPGRADE","green",
        "REMAIN","black",
        "DOWNGRADE","red"
        )
RETURN
SWITCH(TRUE(),
        previous_rating<current_rating, IF(rating_movement<>BLANK(),_result,"red"),
        previous_rating=current_rating,IF(rating_movement<>BLANK(),_result,"black"),
        previous_rating>current_rating,IF(rating_movement<>BLANK(),_result,"green")
)
FontColor = 
IF([Sum of Outstanding Balance]=0,
SWITCH([BackgroundColor],
        "red","red",
        "black","black",
        "green","green"),
        "white"
)


The final resutl is as follows. Hopefully it will meet your needs.

vdengllimsft_1-1736400773141.png

 

Please see the attached pbix for reference.

Best Regards,
Dengliang Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Thanks for the reply from speedramps, please allow me to provide another insight.
Hi @mojekk ,

 

Please refer to the following steps.

 

Create two rating tables, derived from the PREVIOUS RATING and CURRENT RATING fields, and establish a relationships.Use the fields from these two tables as the rows and columns of the matrix.

Previous rating = GENERATESERIES(MIN('Table'[PREVIOUS RATING]),MAX('Table'[PREVIOUS RATING]),1)
Current rating = GENERATESERIES(MIN('Table'[CURRENT RATING]),MAX('Table'[CURRENT RATING]),1)

vdengllimsft_0-1736400217990.png

 

Creates a measure to display the OUTSTANDING BALANCE and uses this measure as the value field of the matrix.

Sum of Outstanding Balance = 
IF (
    MAX ( 'Table'[RATING MOVEMENT] ) <> BLANK (),
    SUM ( 'Table'[OUTSTANDING BALANCE] ),
    0
)

 
Creates measures for the background color and font color to be used for the matrix values.

BackgroundColor = 
VAR rating_movement = MAX('Table'[RATING MOVEMENT])
VAR previous_rating = MAX('Previous rating'[value])
VAR current_rating = MAX('Current rating'[value])
VAR _result = SWITCH(rating_movement,
        "UPGRADE","green",
        "REMAIN","black",
        "DOWNGRADE","red"
        )
RETURN
SWITCH(TRUE(),
        previous_rating<current_rating, IF(rating_movement<>BLANK(),_result,"red"),
        previous_rating=current_rating,IF(rating_movement<>BLANK(),_result,"black"),
        previous_rating>current_rating,IF(rating_movement<>BLANK(),_result,"green")
)
FontColor = 
IF([Sum of Outstanding Balance]=0,
SWITCH([BackgroundColor],
        "red","red",
        "black","black",
        "green","green"),
        "white"
)


The final resutl is as follows. Hopefully it will meet your needs.

vdengllimsft_1-1736400773141.png

 

Please see the attached pbix for reference.

Best Regards,
Dengliang Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

speedramps
Super User
Super User

Download this solution from Onedrive

Click here 

 

 

RAG = 
var mymovemnet = SELECTEDVALUE(Yourdata[RATING MOVEMENT])
 RETURN
 SWITCH(SELECTEDVALUE(Yourdata[RATING MOVEMENT]),
 	"DOWNGRADE","Red",
    "UPGRADE","Green",
    "REMAIN","Grey"
    )

 

speedramps_2-1736365923654.png

 

speedramps_0-1736365794220.pngspeedramps_1-1736365848001.png

 


Please click the [accept as solution] and the thumbs up button. Thank you

 

Appreciate the help, but does not appreciate the tone. Thanks again, but that simple solution has been done previously by me which only coloured cell containing the data and I need even the empty cell are coloured accordingly (as in Excel). Wanted to accept it as solution, but still not answering my initial request. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.