Forum Discussion
Define column in measure based on selected value
- Anonymous2 years ago
Update!
Based on the answer for Yulia, this is not possible to achieve in DAX.
BR Morten
Hi Anonymous ,
I am not sure if I understood your question correctly.
You seem to want to create a slicer to switch between different columns of data in the visual object.
The problem you are experiencing is due to the fact that you cannot use the column name directly in AVERAGE (even if it is stored as a text value in a variable.)
DAX does not support dynamic column references in this way.
Perhaps you can try the following approach to meet your needs.
Based on my understanding above, I created some data:
Please try the following steps:
1.Go to the Power query editor, select all the columns in the table , choose "Unpiovit columns".
2.Apply and close, then use the following code to create a Measure.
Measure =
VAR Selected_Column = SELECTEDVALUE('Table'[Attribute])
RETURN
CALCULATE(AVERAGE('Table'[Value]),
FILTER('Table', SELECTEDVALUE('Table'[Attribute]) = Selected_Column)
)
The field of the slicer is from Table. When you select "A" in the slicer, Result is as below.
Please correct me if I misunderstood your needs.
Best Regards,
Yulia Yan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Yulia,
Thank you for the answer, and yes you have understood the question correctly. It was also my guess that it's simply not possible to do.
In regards to your proposal: That would probably work in this use case, but I want to use the same table for multiple purposes, so that's why I don't want to "unpivot" it as you propose.
BR Morten