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
anacpint
Helper I
Helper I

Switch function not working

Hello,

First, I developed a measure to replace the nulls with zeros.

RFTC_NoBlank = IF(ISBLANK(SUM(Fact_RFTC[Countof])),0,SUM(Fact_RFTC[Countof]))

This the result of the measure.

anacpint_0-1656691148766.png

After this step I created a measure to do the conditional formatting.

ColorSwitchRFT = VAR RFT = VALUES(Fact_RFTC[rft_classification])
RETURN
SWITCH(
TRUE(),
RFT="Correct", "#11A82B",
RFT="Low","#A9CC0D",
RFT="Moderate","#F2CB49",
RFT="New_Requirement", "#12ABDB",
RFT="Severe","#FF6961"
)
And this is the result:
anacpint_1-1656691340079.png
So, this measure doesn't assume the zeros created by the first measure and don't change the color.
The final result should be something like this:
anacpint_2-1656691703307.png

 

I'm working with live connection so I cannot create a calculated column.
Is there any way to solve this?
 
Thanks in advance.
Ana Pinto
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@anacpint , this is my suggestion:

Create a new Calculated Table called dimClassification:

 

dimClassification = VALUES('factRFTC'[Classification])

 

Add a relationship between the dimClassification table and factRFTC table. Make sure the relationship is Many to One, and the direction flows from the dimClassification table to the FactRFTC table.

EylesIT_0-1656935500494.png

The measure that you use for the conditional formatting in the matrix should be changed to this:

 

ColorSwitchRFT = 
    VAR vClassification = SELECTEDVALUE('dimClassification'[Classification])
    RETURN
        SWITCH(
            TRUE(),
            vClassification = "Correct", "#11A82B",
            vClassification = "Low","#A9CC0D",
            vClassification = "Moderate","#F2CB49",
            vClassification = "New_Requirement", "#12ABDB",
            vClassification = "Severe","#FF6961"
        )

 

Then delete the Fact_RFTC[rft_classification] field from the Rows field from the matrix, and add dimClassification[Classification] in its place.

EylesIT_2-1656936267093.png

Set the Conditional Formatting of the RFTC_NoBlank field in the matrix for Background Color to be Format Style "Field Value", and set the "What field should we base this on" to your [RFTC_NoBlank] measure.

 

When I do that with some test data, this is what I get. Note that my test data in FactRFTC has no rows at all for month March 2021, but the cell for {Mar-21, Low} is correctly coloured green because it gets the value for Classification from dimClassification.

Hope this helps.

EylesIT_3-1656936444709.png

 

 

 

View solution in original post

25 REPLIES 25

I cannot create a calculated table or column because I'm working with Live connection with a SSAS database.

What I'm gonna do is to create that dimension directly on the cube and follow all your steps.

Thanks for all your help!

Anonymous
Not applicable

@anacpint , you're welcome. Please update us on whether it worked or not.

Hello @Anonymous,

I followed your suggestion and is working! Combining the classification from the Dim and the measure to replace the blanks, worked fine.

Thank you for your help.

Anonymous
Not applicable

@anacpint , what is the tablename and fieldname on the matrix for the classification? In your ColorSwitchRFT measure you should use the classification column from the dimension table, not the fact table.

I assume in your fact table Fact_RFTC there are no rows that have Fact_RFTC[rft_classification] = "Low"? If that is the case, then when the measure executes "VALUES(Fact_RFTC[rft_classification])", then it will never equal "Low", and so the measure result will never be "#A9CC0D".

@EyIesIT Thanks for your answer! So the fiel used is [rft_classification] and there's no dim for this field.

The problem isn't with the "Low" values, is with the 0 values that came from the measure RFTC_NoBlank.

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.