Forum Discussion
Possible to swap between active/inactive relationships when dealing with two unique fact tables?
- 7 months ago
Hi RenateBK
Few things I would do in this case are as follows.1. The UserRelationship() works only when there is a inactive relationship is present between the tables. Have you created it? Do check that
2. You can handle this with a IF condition or a Switch Condition. One additional thing you would need for this is an additional slicer that defines which relationship to be used.
Assuming there is a table with active relationship and another one with inactive relationship, this is how my DAX would look. I would introduce a slicer that defines which relationship to use.
For ex, let's say we have a dummy slicer giving below options, Source1 and Source2. My requirement is to use Active Relationship when Source1 is selected and Inactive relationship when Source2 is selected
SWITCH(TRUE(), SELECTEDVALUE(Slicer) = "Source1", DISTINCTCOUNT(Table1[IDKey]), SELECTEDVALUE(Slicer) = "Source2", CALCULATE(DISTINCTCOUNT(beds_cases[IDKey]), USERELATIONSHIP(countrydim[IDkey], bed_cases[IDKey])) )Note: You need to replace the Slicer, Source names, table names as per your requirement.
Regards,
- 7 months ago
Hi RenateBK ,
I see in your DAX, you are equating Beds and Tables against the column IDKey, which you said is a Whole Number column. Are you sure you are doing the right thing here?
If it is a Whole Number column, It may not have the values Beds and Tables.
That is something you may have to check and fix !
Hope it helps!
Regards,
- 7 months ago
Hi RenateBK ,
Thanks for reaching out to Microsoft Fabric Community.
As pointed out by RenateBK the SWITCH pattern assumes a separate slicer column containing values such as Beds and Tables. That slicer column is what should be referenced in SELECTEDVALUE.In your current measure, IDKey is a numeric column, so comparing it to text values results in the text versus integer error you are seeing. This is not related to the relationship data types.
To use this approach, you will need a disconnected slicer table with those category values, or otherwise consider a model change such as consolidating the fact tables or using a bridge table.
Hope this helps. Please reach out for further assistance.
Thank you.
Thank you for the feedback! I think I've run into one slight issue (or I am messing this up somehow). This is how I wrote the DAX code:
I get an error saying that the "FactTable" Tables cannot be used for the as it's comparing Text with Integer, however I have doublechecked the relationship table and the IDkeys should all be set to "Whole number", and the keys used for establishing the relationship are all the same type of format.
Am I messing up with my column reference somehow?
Hi RenateBK ,
I see in your DAX, you are equating Beds and Tables against the column IDKey, which you said is a Whole Number column. Are you sure you are doing the right thing here?
If it is a Whole Number column, It may not have the values Beds and Tables.
That is something you may have to check and fix !
Hope it helps!
Regards,