Forum Discussion

PeRoma's avatar
PeRoma
Frequent Visitor
2 years ago

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

1123111 
2 222 
3345  
4456 456
5567 876
6 333333
7789444 
8900555 
910111011 
101122  
111233  
12  654
131455 543
141566777432
15 888 
1617881788321
1718991110 

 

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

  • 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()
        )
    )
    
    • PeRoma's avatar
      PeRoma
      Frequent 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

  • 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!

    • PeRoma's avatar
      PeRoma
      Frequent 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