The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hello! I need to use measure that returns the column name from one take using selectedvalue, and use this columnname to get the column. Example:
Here is my first table:
id | attribute |
1 | Purchase |
1 | Emotion |
1 | Likability |
2 | Purchase |
2 | Likability |
2 | Emotion |
I will use attribute column as a filter, those 3 attributes are the column names of my second table:
id | Purchase | Likability | Emotion | ||
1 | 0.342 | 0.835 | 0.756 | ||
2 | 0.432 | 0.657 | 0.235 | ||
3 | 0.754 | 0.654 | 0.765 |
I need to create a formula, to calculated the average of one specific column based on attribute column from the first table:
so I now use:
var filter_attribute = selectedvalue('1 table'[attribute])
var mean = calculate(average( '2 table'[*filter_attribute*] ))
What do I need to put filter_attribute(column name) to DAX will consider it as the column named like this? Thanks in advance!
Solved! Go to Solution.
@Anonymous I would highly recommend that you unpivot those three columns in your 2nd table and then this problem becomes trivial. Alternatively you would have to do this:
var filter_attribute = selectedvalue('1 table'[attribute])
var mean =
SWITCH(__filter_attribute,
"Purchase",calculate(average( '2 table'[Purchase] )),
"Likeability",calculate(average( '2 table'[Likeability] )),
"Emotion",calculate(average( '2 table'[Emotion] )),
)
@Anonymous I would highly recommend that you unpivot those three columns in your 2nd table and then this problem becomes trivial. Alternatively you would have to do this:
var filter_attribute = selectedvalue('1 table'[attribute])
var mean =
SWITCH(__filter_attribute,
"Purchase",calculate(average( '2 table'[Purchase] )),
"Likeability",calculate(average( '2 table'[Likeability] )),
"Emotion",calculate(average( '2 table'[Emotion] )),
)
User | Count |
---|---|
24 | |
9 | |
8 | |
7 | |
6 |
User | Count |
---|---|
29 | |
11 | |
11 | |
9 | |
9 |