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

USERELATIONSHIP with variable (or table[column] as variable

I have a scenario where I'm dynamically using relationships, with the USERELATIONSHIP function.  The nature of this is that I'll have many possible combinations or relationships to use (around 100) so rather writing an enormous SWITCH statement I'd like to use variables in the USERELATIONSHIP function, something like:
var col1='myTable'[myCol]

var col2='yourTable'[yourCol]
USERELATIONSHIP(col1, col2)

 

Does anyone know if anything close to this is possible?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

The relationships between tables must exist and the relationship is not active when use the function USERELATIONSHIP. Do you want to "create" the relationship base on different fields in different conditions? 

UseRelationship or Role-Playing Dimension; Dealing with Inactive Relationships in Power BI

Dynamic relationships based on the selection

Best Regards

View solution in original post

2 REPLIES 2
vhatp
Advocate I
Advocate I

I am sorry but I don't think this answer is a solution. It is rather a question, to which the answer is "no".
I believe the author did NOT want to CREATE relationships, but just switch between already existing (inactive) ones.

In my opinion, the author's suggestion would be the ideal solution, but it gives error - USERELATIONSHIP does not accept such a variable as column argument.
The trouble is, I can't even use the SWITCH/IF within the CALCULATE statement to select one of the possible USERELATIONSHIP definitions (pairs), because USERELATIONSHIP may only be used within CALCULATE statement, not IF/SWITCH.
I tried moving the switch outside the CALCULATE statment, that did not trigger any error, but did not yield the desired result either.
So I'd be also thankful for some insight how to solve this - set up conditional relationships based on a variable.

Anonymous
Not applicable

Hi @Anonymous ,

The relationships between tables must exist and the relationship is not active when use the function USERELATIONSHIP. Do you want to "create" the relationship base on different fields in different conditions? 

UseRelationship or Role-Playing Dimension; Dealing with Inactive Relationships in Power BI

Dynamic relationships based on the selection

Best Regards

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors