Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Can I set a column name as variable in DAX?

Hi there 🙂   I want to be able to change the column name referenced in a DAX formula - for example here I want to be able to change the column name where it says "YTD", so that this is based on a ...
  • AllisonKennedy's avatar
    6 years ago

    Anonymous Not exactly within the square brackets, but you could try a SWITCH function to get the result you're after: 

     

    Here's an example I made up: 

     

    Test Slicer Column =


    SUMX(FILTER('Blank Values',
    VAR _Column =
    SWITCH(SELECTEDVALUE(Slicer[Column Select])
    , "Year", 'Blank Values'[Year]
    , "Key", 'Blank Values'[Key])
    RETURN
    CONTAINSSTRING(_Column ,"2018")), 'Blank Values'[Value])