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 nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.
| User | Count |
|---|---|
| 27 | |
| 23 | |
| 18 | |
| 18 | |
| 15 |
| User | Count |
|---|---|
| 62 | |
| 44 | |
| 42 | |
| 37 | |
| 37 |