The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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