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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
COG1
Frequent Visitor

Switch with Selected value for Conditional formatting

I'm using the Switch function to define conditional formatting for icons in a matrix as follows:

 

COG1_1-1687537089349.png

 

This works well, however in my matrix table i'm also using a slicer to switch between which measure is displayed (e.g. i toggle between the sales mesaure displayed in the matrix, and the sales % mesaure).

I want to apply seperate thresholds for conditional formatting icons for each measure.

 

I've tried incorporating SELECTEDVALUE to the measure, but i can;'t figure it out. Can you advise how to combine selectedvalue and switch to achieve this (or an alternative?)

 

e.g.

 

Sales Icon =

Switch(SELECTEDVALUE

TRUE(),

[SALES] > 1000, "TrafficHighLight",

[SALES] < -100, "TrafficLowLight",

[SALES%] > 5%, "TrafficHighLight",

[SALES%] < -5% "TrafficLowLight",

"TrafficMediumLight"

)

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@COG1,

 

Try this solution. The logic in the first variable is explained here:

 

https://www.sqlbi.com/blog/marco/2022/06/11/using-selectedvalue-with-fields-parameters-in-power-bi/ 

 

1. Create measure:

 

Sales Icon = 
VAR vSelectedMeasure =
    SELECTCOLUMNS (
        SUMMARIZE ( Parameter, Parameter[Parameter], Parameter[Parameter Fields] ),
        "Parameter", Parameter[Parameter]
    )
VAR vResult =
    SWITCH (
        vSelectedMeasure,
        "Sales",
            SWITCH (
                TRUE,
                [Sales] > 1000, "TrafficHighLight",
                [Sales] < -100, "TrafficLowLight"
            ),
        "Sales %",
            SWITCH (
                TRUE,
                [Sales %] > .05, "TrafficHighLight",
                [Sales %] < -.05, "TrafficLowLight"
            )
    )
RETURN
    vResult

 

2. In the format pane of the visual (matrix in this example), go to Cell elements, enable Icons, click the fx button, and select the Sales Icon measure:

 

DataInsights_0-1687965281935.png

DataInsights_1-1687965334701.png

 

Do this for each measure in your field parameter (you have to individually select each value in your field parameter slicer and apply these steps). You can also set conditional formatting via the user interface, but a measure enables you to define the logic in one place (easier maintenance).

 

Here's a list of icon names for conditional formatting:

 

https://radacad.com/power-bi-icon-names-for-conditional-formatting-using-dax 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@COG1,

 

Try this solution. The logic in the first variable is explained here:

 

https://www.sqlbi.com/blog/marco/2022/06/11/using-selectedvalue-with-fields-parameters-in-power-bi/ 

 

1. Create measure:

 

Sales Icon = 
VAR vSelectedMeasure =
    SELECTCOLUMNS (
        SUMMARIZE ( Parameter, Parameter[Parameter], Parameter[Parameter Fields] ),
        "Parameter", Parameter[Parameter]
    )
VAR vResult =
    SWITCH (
        vSelectedMeasure,
        "Sales",
            SWITCH (
                TRUE,
                [Sales] > 1000, "TrafficHighLight",
                [Sales] < -100, "TrafficLowLight"
            ),
        "Sales %",
            SWITCH (
                TRUE,
                [Sales %] > .05, "TrafficHighLight",
                [Sales %] < -.05, "TrafficLowLight"
            )
    )
RETURN
    vResult

 

2. In the format pane of the visual (matrix in this example), go to Cell elements, enable Icons, click the fx button, and select the Sales Icon measure:

 

DataInsights_0-1687965281935.png

DataInsights_1-1687965334701.png

 

Do this for each measure in your field parameter (you have to individually select each value in your field parameter slicer and apply these steps). You can also set conditional formatting via the user interface, but a measure enables you to define the logic in one place (easier maintenance).

 

Here's a list of icon names for conditional formatting:

 

https://radacad.com/power-bi-icon-names-for-conditional-formatting-using-dax 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.