Forum Discussion

dokat's avatar
dokat
Post Prodigy
2 years ago
Solved

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.

  • tharunkumarRTK's avatar
    tharunkumarRTK
    2 years ago

    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 condition


    Measure 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

  • 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-msft's avatar
    v-yanimei-msft
    Community 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.

    • tharunkumarRTK's avatar
      tharunkumarRTK
      Super 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 condition


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