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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Dynamic text column selection based on slicer selection in Power BI

Hi,

 

I am trying to create a dynamic column, where different text column would be selected, based on single value selected in slicer.

Example, when slicer Function = 'HR' then 'HR Score' column, for other functions 'Other Score' column would be selected.  My intention is to use this newly created dynamic column as a legend in charts. Function, Score are dimension tables connected to a fact table. Thus, basically, for score ID (common in dim and fact table), based on Function selected in the slicer, I want to switch between the two Score Description columns. 

 

Truly appreciate your help.

 

DebSJ_1-1618674876460.png

 

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your description, I think you can try to create a new table for the slicer and create a measure to achieve this, you can try this:

  1. Click “Enter data” to create a new table:

v-robertq-msft_0-1618802384111.png

 

  1. Create a measure:

 

Dynamic column =

var _selectedfunction=SELECTEDVALUE(Slicer[Function])

return

SWITCH(

    _selectedfunction,

    "HR",MAX('Table'[HR Score]),

    "Other",MAX('Table'[Other Score]),

BLANK())

 

  1. Create a table chart and a slicer and place them like this:

v-robertq-msft_1-1618802384116.png

v-robertq-msft_2-1618802384121.png

 

And you can get what you want.

You can download my test pbix file below

Thank you very much!

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your description, I think you can try to create a new table for the slicer and create a measure to achieve this, you can try this:

  1. Click “Enter data” to create a new table:

v-robertq-msft_0-1618802384111.png

 

  1. Create a measure:

 

Dynamic column =

var _selectedfunction=SELECTEDVALUE(Slicer[Function])

return

SWITCH(

    _selectedfunction,

    "HR",MAX('Table'[HR Score]),

    "Other",MAX('Table'[Other Score]),

BLANK())

 

  1. Create a table chart and a slicer and place them like this:

v-robertq-msft_1-1618802384116.png

v-robertq-msft_2-1618802384121.png

 

And you can get what you want.

You can download my test pbix file below

Thank you very much!

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @selimovd ,

 

Thank you for you help. However,  I get the following error message: 


MdxScript(Model) (153, 14) Calculation error in measure 'Score'[MyDynamicMeasure]: The function SUM cannot work with values of type String.

 

Any idea about the function to be passed instead of SUM?

 

Best regards,

Deb

 

Hey @Anonymous .

 

it depends on what you want to show.

What should be the result that is shown? I used SUM of a column as an example. What should your result be when not "HR" is selected from the slicer?

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
selimovd
Super User
Super User

Hey @Anonymous ,

 

try the following measure and adapt it to your tables:

MyDynamicMeasure =
VAR vSelected = SELECTEDVALUE( Slicer[Function] )
VAR vResult =
    SWITCH(
        vSelected,
        "HR", SUM( myTable[HR Score] ),
        SUM( myTable[Other Score] )
    )
RETURN
    vResult

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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