Forum Discussion

sjl_74's avatar
sjl_74
Microsoft Employee
2 years ago
Solved

Using a switch statement to select a column

I am completely stumped. I'm trying to use… a slicer to select a single value (this works) Then use that value with a SWITCH statement to select a column (this doesn't work)   How I've set this ...
  • Greg_Deckler's avatar
    2 years ago

    sjl_74 See the below formula and attached PBIX on how to fix. What I don't understand is why you aren't getting an error in your measure formula because you are referencing a column without an aggregation and that's not really a thing generally.

    Select_Column = 
    VAR SelectedColumn = SELECTEDVALUE(Slicer_Table[Slicer_Options])
    RETURN
        SWITCH(
            SelectedColumn,
            1, MAX('Data_Table'[Column_1]),
            2, MAX(Data_Table[Column_2])
        )