Forum Discussion
sjl_74
2 years agoMicrosoft Employee
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 ...
- 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]) )
Greg_Deckler
2 years agoCommunity Champion
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])
)
- sjl_742 years agoMicrosoft Employee
The Select_Column measure worked perfectly.
Thank you so much Greg_Deckler !