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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Using variable name as column name in DAX

I'm trying to build dynamic RCL in PowerBI. Below is my table structures.

 

AccessControlTable 

MailIDEntityEntityValue
jan_doeUnitABC
joe_doeSubUnitDEF

 

ProjectDetails

ProjectCodeUnitSubUnit
PID100ABCDEF
PID200XYZABC

 

RLS DAX Query:

 

=
VAR NEWTABLE = CALCULATETABLE (AccessControlTable,PATHCONTAINS(LOWER(AccessControlTable[MailID]),
SUBSTITUTE(LOWER(USERNAME()),"itlinfosys\","")))

VAR ENTITY = SELECTCOLUMNS(NEWTABLE,"Entity", [Entity])
VAR ENTITYVALUE = SELECTCOLUMNS(NEWTABLE,"EntityValue", [EntityValue])

RETURN CONTAINS(ProjectDetails,ProjectDetails[ENTITY],ENTITYVALUE) // ENTITY is the variable name

 

Above code doesn't work, throwing error as below.

ahmmadsuroor_0-1665762659881.png

I tried using `SWITCH` and it works, but since I have 100s of ENTITY types it's not efficient method.

 

RETURN SWITCH(
    TRUE(),
    ENTITY = "Unit", CONTAINS(ProjectDetails,ProjectDetails[Unit],ENTITYVALUE),
    ENTITY = "SubUnit", CONTAINS(ProjectDetails,ProjectDetails[SubUnit],ENTITYVALUE),
    ENTITY = "Category1", CONTAINS(ProjectDetails,ProjectDetails[Category1],ENTITYVALUE),
    ENTITY = "Category2", CONTAINS(ProjectDetails,ProjectDetails[Category2],ENTITYVALUE),
    ...
)

 

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I don't think it's possible to dynamically reference a column using a string variable in DAX, unfortunately. (Anyone please correct me if this is not true.)

 

I'd recommend unpivoting your ProjectDetails table to match the shape of the AccessControlTable like this:

AlexisOlson_0-1665786152819.png

 

Then you should be able to write something like

CONTAINSROW ( { ENTITY, ENTITYVALUE }, ProjectDetails[Entity], ProjectDetails[EntityValue] )

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

I don't think it's possible to dynamically reference a column using a string variable in DAX, unfortunately. (Anyone please correct me if this is not true.)

 

I'd recommend unpivoting your ProjectDetails table to match the shape of the AccessControlTable like this:

AlexisOlson_0-1665786152819.png

 

Then you should be able to write something like

CONTAINSROW ( { ENTITY, ENTITYVALUE }, ProjectDetails[Entity], ProjectDetails[EntityValue] )

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.