Forum Discussion
Dax If statement not working correctly.
Hi,
I have below dax code i'd like it change background color of the shape to red (rgba(255, 255, 255, 1)) when "Last Month" is selected in slicer or else transperant background color rgba(255, 255, 255, 0).
Legend Measure =
VAR SelectedSlicerValue = SELECTEDVALUE('Slicer'[Slicer Selection])
RETURN
IF (
SELECTEDVALUE('Slicer'[Slicer Selection]) = "Last Month",
"rgba(255, 255, 255, 1)" ,
"rgba(255, 255, 255, 0)"
) However regardless of Last Month selection in the slicer it always returns transparent background rgba(255, 255, 255, 0). Does anyone know why if function may not be working correctly.
I put the measure under Shape-Style-Color-Format Style-Field Value.
v-yanimei-msft
Power BI accepts "rgba(255,255,255,0)", as you can see in the below image. I created two measures, [measure 2]and [measure 3] and used them in the background color for the shapes. And if you you observe both are working as per the conditionMeasure 3 = if (10<1, "rgba(255,255,255,1)","rgba(255,255,255,0)") Measure 2 = if (10>1, "rgba(255,255,255,1)","rgba(255,255,255,0)")
3 Replies
- tharunkumarRTKSuper User
dokat
Did you validate your if statement? I would suggest you to put this measure in a card visual and change the selection in the slicer and validate it. If you measure is working as per your expection then please try to share pbix file for futher testing.If the post helps please give a thumbs up
If it solves your issue, please accept it as the solution to help the other members find it more quickly.
Tharun
- v-yanimei-msftCommunity Support
Hi dokat ,
Thank you for giving a specific description of the problem and the associated code. Through your description, I have found out what the problem is. The steps to resolve the issue are as follows.
1.Modify the code.
Legend Measure = VAR SelectedSlicerValue = SELECTEDVALUE('Slicer'[Slicer Selection]) RETURN IF ( SELECTEDVALUE('Slicer'[Slicer Selection]) = "Last Month", // "rgba(255, 255, 255, 1)" , It cannot be recognized. "red", // "rgba(255, 255, 255, 0)", It cannot be recognized. "transparent" )2. Apply conditional formatting. Learn about Apply conditional table formatting in Power BI - Power BI | Microsoft Learn.
3. The outcome is as follows.
Best Regards,
Caroline Mei
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- tharunkumarRTKSuper User
v-yanimei-msft
Power BI accepts "rgba(255,255,255,0)", as you can see in the below image. I created two measures, [measure 2]and [measure 3] and used them in the background color for the shapes. And if you you observe both are working as per the conditionMeasure 3 = if (10<1, "rgba(255,255,255,1)","rgba(255,255,255,0)") Measure 2 = if (10>1, "rgba(255,255,255,1)","rgba(255,255,255,0)")