Forum Discussion

Hoping's avatar
Hoping
Helper III
2 years ago
Solved

Dynamic Measures based on Slicer Selection

Hi, 

 

I am trying to display multiple measures based on slicer selection in a matrix. 

 

I am using something similar to this solution - https://goodly.co.in/change-measures-using-slicer-powerbi/

 

The SWITCH is based on VALUES in order to allow multiple selection.   This solution works but only in a matrix when I can display each measure selected in a column i.e I can display multiple measures at the same time.

 

In case of a table visualisation, if I choose multiple options, I get an error - A table of multiple values was supplied where a single value was selected.

 

What is the reason it is failing?  As an alternate option I used Field parameters and selected all the insividual measures and added the field parameter to the table as a column. This worked like magic. 

 

Why did my own measure table with a column as measures and SWITCH statement (as shown in the link above) solution not work in a table visualisation ?

 

What is the difference between these solutions ?

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Hoping ,

    The VALUES function returns a table of values when used in a table context, and when multiple options are selected in a slicer, Power BI attempts to pass a table with multiple values to the SWITCH statement instead of a single value. However, the SWITCH statement is designed to use a single value, not a table of values. This is why you get the error message “A table of multiple values was supplied where a single value was expected” when you try to use the SWITCH statement in a table visualisation.
    On the other hand, using field parameters and adding them as columns to the table is effective because it allows you to select multiple measures and display them in a single column. This is because field parameters are designed to accept multiple values and return a single value.

    Best Regards,

    Dino Tao

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

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Hoping ,

    The VALUES function returns a table of values when used in a table context, and when multiple options are selected in a slicer, Power BI attempts to pass a table with multiple values to the SWITCH statement instead of a single value. However, the SWITCH statement is designed to use a single value, not a table of values. This is why you get the error message “A table of multiple values was supplied where a single value was expected” when you try to use the SWITCH statement in a table visualisation.
    On the other hand, using field parameters and adding them as columns to the table is effective because it allows you to select multiple measures and display them in a single column. This is because field parameters are designed to accept multiple values and return a single value.

    Best Regards,

    Dino Tao

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