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
Stcorda
Frequent Visitor

Switch column value selecting from slicer

Hi, I am looking for a way to switch column name & value according to the slicer selection. 

To switch value i created this measure:  

YTD Reference = SWITCH
(VALUES('Scenari'[Reference Scenario]),
"Act",[YTD ACT],
"F(6+6)",[YTD FCST (6+6)],
"F(9+3)",[YTD FCST (9+3)],
"F(3+9)",[YTD FCST (3+9)],
"BDG",[YTD BDG]
)
 
and it seems work for values, but i missed the name in the table. Could you suggest me an alternative so that the header name and value in the table changes according to the slicer selection?
 
e.g. YTD Reference field in the table should display YTD ACT as selected in the slicere
 
Stcorda_1-1701264367481.png

 

Stcorda_0-1701264194226.png

thanks a lot!

 

 

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

You can do that by creating a field parameter for each of the sets of measures in your slicers.

https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters

Go to Modeling > New parameter > Fields

jdbuchanan71_0-1701265631251.png

Name the parmeter and add the measures you want in that selection.

jdbuchanan71_1-1701265662073.png

Add the paramater to a slicer and to to your visual.  I would set the slicer to drop down single select.  When you change the measure selected in the slicer the column name changes in the table.

jdbuchanan71_2-1701265731423.png

 

 

View solution in original post

jdbuchanan71
Super User
Super User

Sure, this is going to look more complicated that it really is probably.  There is a bug? with field parameters where you cannot use SELECTEDVALUE to read the selection.  Here is an article on it: https://www.sqlbi.com/blog/marco/2022/06/11/using-selectedvalue-with-fields-parameters-in-power-bi/

That means we have to use the longer SELECTCOLUMNS SUMMARIZE route shown in that article. 

We use that to see what is selected in the Reference Scenario and Comparison Scenario 1 then use SWITCH to get those amounts and finally do the compare.

YTD Ref - Comp 1 = 
VAR _RefSelection =
    SELECTCOLUMNS (
        SUMMARIZE (
            'Reference Scenario',
            'Reference Scenario'[Reference Scenario],
            'Reference Scenario'[Reference Scenario Fields]
        ),
        'Reference Scenario'[Reference Scenario]
    )
VAR _CompSelection =
    SELECTCOLUMNS (
        SUMMARIZE (
            'Comparison Scenario 1',
            'Comparison Scenario 1'[Comparison Scenario 1],
            'Comparison Scenario 1'[Comparison Scenario 1 Fields]
        ),
        'Comparison Scenario 1'[Comparison Scenario 1]
    )
VAR _Ref =
    SWITCH (
        _RefSelection,
        "YTD ACT", [YTD ACT],
        "YTD FCST (6+6)", [YTD FCST (6+6)],
        "YTD FCST (9+3)", [YTD FCST (9+3)],
        "YTD FCST (3+9)", [YTD FCST (3+9)],
        "YTD BDG", [YTD BDG]
    )
VAR _Comp =
    SWITCH (
        _CompSelection,
        "YTD ACT", [YTD ACT],
        "YTD FCST (6+6)", [YTD FCST (6+6)],
        "YTD FCST (9+3)", [YTD FCST (9+3)],
        "YTD FCST (3+9)", [YTD FCST (3+9)],
        "YTD BDG", [YTD BDG]
    )
RETURN
    _Ref - _Comp

jdbuchanan71_0-1701355230060.png

 

Please note, it will look like the DAX is throwing an error, even though it works fine:

LooksLikeError.png

 

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

Here is my sample file for you to take a look at.

 

jdbuchanan71
Super User
Super User

Sure, this is going to look more complicated that it really is probably.  There is a bug? with field parameters where you cannot use SELECTEDVALUE to read the selection.  Here is an article on it: https://www.sqlbi.com/blog/marco/2022/06/11/using-selectedvalue-with-fields-parameters-in-power-bi/

That means we have to use the longer SELECTCOLUMNS SUMMARIZE route shown in that article. 

We use that to see what is selected in the Reference Scenario and Comparison Scenario 1 then use SWITCH to get those amounts and finally do the compare.

YTD Ref - Comp 1 = 
VAR _RefSelection =
    SELECTCOLUMNS (
        SUMMARIZE (
            'Reference Scenario',
            'Reference Scenario'[Reference Scenario],
            'Reference Scenario'[Reference Scenario Fields]
        ),
        'Reference Scenario'[Reference Scenario]
    )
VAR _CompSelection =
    SELECTCOLUMNS (
        SUMMARIZE (
            'Comparison Scenario 1',
            'Comparison Scenario 1'[Comparison Scenario 1],
            'Comparison Scenario 1'[Comparison Scenario 1 Fields]
        ),
        'Comparison Scenario 1'[Comparison Scenario 1]
    )
VAR _Ref =
    SWITCH (
        _RefSelection,
        "YTD ACT", [YTD ACT],
        "YTD FCST (6+6)", [YTD FCST (6+6)],
        "YTD FCST (9+3)", [YTD FCST (9+3)],
        "YTD FCST (3+9)", [YTD FCST (3+9)],
        "YTD BDG", [YTD BDG]
    )
VAR _Comp =
    SWITCH (
        _CompSelection,
        "YTD ACT", [YTD ACT],
        "YTD FCST (6+6)", [YTD FCST (6+6)],
        "YTD FCST (9+3)", [YTD FCST (9+3)],
        "YTD FCST (3+9)", [YTD FCST (3+9)],
        "YTD BDG", [YTD BDG]
    )
RETURN
    _Ref - _Comp

jdbuchanan71_0-1701355230060.png

 

Please note, it will look like the DAX is throwing an error, even though it works fine:

LooksLikeError.png

 

jdbuchanan71
Super User
Super User

Because you can select more that 1 item to be visable from a field prameter you can't do math on them directly.  You would have to write a measure that reads the selection in the field paramaters and returns those measures to do the compare on.

Ok, got it.. May i ask you a suggestion on dax code formula which can be used? Thanks in advance, I am trying to walk through first times

jdbuchanan71
Super User
Super User

You can do that by creating a field parameter for each of the sets of measures in your slicers.

https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters

Go to Modeling > New parameter > Fields

jdbuchanan71_0-1701265631251.png

Name the parmeter and add the measures you want in that selection.

jdbuchanan71_1-1701265662073.png

Add the paramater to a slicer and to to your visual.  I would set the slicer to drop down single select.  When you change the measure selected in the slicer the column name changes in the table.

jdbuchanan71_2-1701265731423.png

 

 

Thanks! it helps a lot, may i do arithmetic between parameters? 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.