Forum Discussion
create column with DAX using paramters as identifier for column
Hi all,
I would like to copy a column using DAX. The problem is that the column is selected as a parameter.
Example:
Nummer AA BB CC
| 1 | 123 | 111 | |
| 2 | 222 | ||
| 3 | 345 | ||
| 4 | 456 | 456 | |
| 5 | 567 | 876 | |
| 6 | 333 | 333 | |
| 7 | 789 | 444 | |
| 8 | 900 | 555 | |
| 9 | 1011 | 1011 | |
| 10 | 1122 | ||
| 11 | 1233 | ||
| 12 | 654 | ||
| 13 | 1455 | 543 | |
| 14 | 1566 | 777 | 432 |
| 15 | 888 | ||
| 16 | 1788 | 1788 | 321 |
| 17 | 1899 | 1110 |
I have defined a field parameter containing the column names "AA", "BB" and "CC". The column is selected by this parameter.
There is another table (T2) containing only the numbers.
Is there a way to define a new column in T2 that contains the values of the selected column?
My final goal is to copy 2 columns and compare the values. Any idea to do this without the creation of the columns is highly wellcome. I want to present a table visual containing both selected columns and a column for comparison.
Thank you for any help or hint.
PeRoma
5 Replies
- Sahir_Maharaj
Super User
Hello PeRoma,
Can you please try this:
CalculatedTable = ADDCOLUMNS( SUMMARIZE(T1, T1[Nummer]), "SelectedValue", SWITCH(TRUE(), SelectedColumn = "AA", CALCULATE(SUM(T1[AA])), SelectedColumn = "BB", CALCULATE(SUM(T1[BB])), SelectedColumn = "CC", CALCULATE(SUM(T1[CC])), BLANK() ) )- PeRomaFrequent Visitor
Hi Sahir,
Thank you for your response.
But sorry, this does not answer my question. My goal to copy the column into table T2. All the values.
If I e.g. select column "AA" from table T1- at run time by any means I want to copy only this column into table T2. The problem is, I don't know how to reference a column dynamically with a parameter, measure or by any other means. This referenced column should then be copied into table T2.In other words: I have no problem to reference columns within DAX by just naming them. But I want to reference to a column that is only selected at run time. And I want to copy this column.
Thank you for your effort. Do you have any idea based on this explanation?
Best
peroma
- StrategicSavvy
Resolver II
Hi,
I think it is not possible in DAX to reference dynamically columns in calculatd tables because they always need to have data copied. I think If you want this you will need to copy all the columns AA, BB, CC and then you can dynamically reference this new calculated table.
Hope it helps!
- PeRomaFrequent Visitor
Hi Savvy,
Thank you for your reply. I was afraid that this would not be possible. But gave me some hope that I can reach my final goal: My goal is, to compare the columns. In the example above there would be TRUE for row 4, 9 and 16 when comparing AA wigh BB. Is it possible to do this comparison e.g. via function EXACT and reference the columns at run time?
Thank you once more for your reply.
Best regards
peroma
- StrategicSavvy
Resolver II
Hi PeRoma,
I think with this goal in mind you can use measure with 2 parametes defined in disconnected table.
Here is the screenshot:
Attached pbix:
https://drive.google.com/file/d/1CbcK9erUvMcMJ6jFqvS-6OTR9LdRrTSt/view?usp=sharing
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: www.linkedin.com/in/lukasz-kozdron