Forum Discussion
Selecting a column from a selected value
Hi, I am completely tearing my hair out here. I have no idea why this doesn't work.
Basically, I am trying to select a column based on a selected value (which is in turn, chosen via slicer) using a switch statement. Here is my DAX code that DOES NOT WORK (Table & column names edited for anonymity):
Here some of the changes I made to troubleshoot:
1) Changing the variable "quarter" to one of the values used in the SWITCH statement:
Works! But, I don't want to just select 1 value, I want the selected value to change. So, no good. It proves that the switch statement CAN work.
2) Converting the SELECTEDVALUE to a string:
DOESN'T WORK
3) Making a test measure where it outputs a number depending on the SELECTEDVALUE:
WORKS! But I don't need numbers, I need it to select the column. (Note, this measure also works if I replace each letter with an aggregation, for example SUM('MyTable'[Column Q1]), but I don't want an aggregation, I want the whole column.)
4) Using the TestMeasure to return a number which is then fed into the switch statement for selecting a column
SO, selecting a column based on a switch statement works IF the variable is set to a constant.
AND, I can output different values based on the SELECTEDVALUE using a switch statement (in a measure)
BUT I can't combine these two in order to select a column with a SWITCH statement!!!
What is happening here??? I feel like I'm going completely insane!!! Help!!!
4 Replies
- RameezM1984New Member
Hello
Did u get the solution for the above?
I am also facing the same problem..if you have a solution ..kindly share
- DataInsights
Super User
Are you trying to dynamically select a column to display in a visual? If so, field parameters are a great option:
https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters
Or, are you trying to dynamically select a column's value for further use in your measure? It's worth noting that a calculated column can't recognize a slicer selection, so a measure is the only option.
- rwalkerNew Member
I am trying to dynamically select a column to display in a visual. I clicked your link but for me there is no "Preview Features" in the options menu, so I can't do it.
Is there a way to do this with a measure instead of a calculated column? I want all the rows to display in a visual, not an aggregation.
- DataInsights
Super User
What version of Power BI Desktop do you have? If you don't see "Field parameters" below, upgrade Power BI Desktop: