Forum Discussion

mojekk's avatar
mojekk
Frequent Visitor
1 year ago
Solved

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:

 

 

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. 

 

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    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)

     

    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.

     

    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.

3 Replies

  • 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"
        )

     

     

     


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

     

    • mojekk's avatar
      mojekk
      Frequent Visitor

      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. 

  • Anonymous's avatar
    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)

     

    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.

     

    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.