Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

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 slicer selection

 

djalexr_0-1600355286864.png

Its easy enough to change the other values (e,.g. I made a formula that uses a slicer input instead of the hard coded "Turnover" value in the above formula...but I'm wondering if its possible to also make the column name in square brackets a variable? 

Is this possible?

 

Thank You!!

Alex

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

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

 

AllisonKennedy_0-1600605935512.png

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])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Thanks very much for this!  Yes I was able to work around this using the SWITCH function.

 

Thanks again

 

Alex

You're welcome!

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

AllisonKennedy
Super User
Super User

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

 

AllisonKennedy_0-1600605935512.png

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])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

I know I'm a Very Late to the party. But is it feasible to obtain the pbix example file that does this?

don't worry , I find it how to do it ? 🙂

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.