Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowData Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more
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?
Solved! Go to Solution.
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
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.
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
Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.
Check out the May 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 22 | |
| 21 | |
| 20 | |
| 19 | |
| 13 |
| User | Count |
|---|---|
| 58 | |
| 50 | |
| 38 | |
| 31 | |
| 27 |