Forum Discussion

iplaygod's avatar
iplaygod
Icon for Resolver I rankResolver I
7 years ago

DAX: Refer to column using string or similar

I have a table with several columns (no surprise)


I would like to know if I can refer to column names by using a string, instead of a literal / raw reference.
I want to dynamically be able to choose what column I am using / referencing inside my measures.


So normally I would write
salesTable[nameOfColumn]

to reference a specific column.
However, I would like to do something like

VAR myColumnName = "columnOne"
//and then use that string variable inside the column reference:
salesTable[ myColumnName ] = 1

Is that possible?

or could I achieve the same thing by using quotes somehow?
like
"salesTable[myColumnName]" = 1
so that the whole expression is a string instead?

Please give me some tips and example code.
Thanks

1 Reply

  • iplaygod unfortunately it is not possible but you can use if or switch conditions to refer to different columns.