Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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?

2 Replies

  • vhatp's avatar
    vhatp
    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.