Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Making Switch function return a column in a table and not a measure (PowerBI DAX)

What I'm trying to do is to change measures using slicers in Power BI Desktop. I have found some examples of people who have done that (for instance this ) .

What they do is that they create a table where there are ID and Measure names. The 'Measure names' column of this table will be used as field value in the filter of the visualization. Then, they create a switch function that, given a certain value in the filter, switch the value in the filter to a measure. You can see an example below:

Measure Value = SWITCH(
                            MIN('Dynamic'[Measure ID]) ,
                            1,[Max Temp],
                            2,[Min Temp],
                            3,[Air Pressure],
                            4,[Rainfall],
                            5,[Wind Speed],
                            6,[Humidity]
                            )

Where 'Dynamic' is a group containing a measure ID and a Measure name:

Dynamic:

Measure ID | Measure Name
1          |  Max Temp
2          |  Min Temp
3          |  Air Pressure
4          |  Rainfall
5          |  Wind Speed
6          |  Humidity

All of the 'Measure Name' are measures as well.

My problem is: I have too many columns (400!) and I cannot turn them into measures one by one. It will take days. I was thinking that maybe I could use the switch function so that it returns the column in the table and NOT the corresponding measure. However I cannot just insert 'Name of the table'['Name of the column'] in the switch function as result parameter.

Does anyone know how to make the function Switch return a column and not a measure? (Or any other suggestion)

5 Replies