Forum Discussion

RenateBK's avatar
RenateBK
Icon for Helper II rankHelper II
7 months ago
Solved

Possible to swap between active/inactive relationships when dealing with two unique fact tables?

Hello,    My company has split up its data into separate fact tables based on case categories, however they would like to see it all in one single report.   I'm currently trying to create a dashb...
  • Thejeswar's avatar
    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,

  • Thejeswar's avatar
    Thejeswar
    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,

  • v-veshwara-msft's avatar
    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.