Forum Discussion

conniedevina's avatar
conniedevina
Helper I
10 months ago
Solved

To connect date with different datekey from same table

Hi,    I am having this kind of fact_table ID category_a category_b categoryA_date categoryB_date 12345 healthy non-healthy 2024-01-01 2024-03-01 12345 sick healthy 2024-05-01 ...
  • Royel's avatar
    10 months ago

    Hi conniedevina  yes it is possible to connect different data columns for certain calculation using DAX USERELATIONSHIP functions 

     

    Results: 

     

    Model Relationships:

    DateTable[Date] = CategoryA_Date (Active)

    DateTable[Date] = CategoryB_Date (In-Active)

     

    Dax: 

    CategoryA = 
    CALCULATE (
    SELECTEDVALUE ( fact_table[category_a] )
    )
    
    CategoryB = 
    CALCULATE (
    SELECTEDVALUE ( fact_table[category_b] ),
    USERELATIONSHIP ( fact_table[categoryB_date], DateTable[Date] )
    )

     

    Small Correction: Your Date table date format are not same as Fact table (CategoryA_Date, CategoryB_Date)

    Here is corrected date for fact table 

     

    Find this helpful? ✔ Give a Kudo • Mark as Solution – help others too!

  • danextian's avatar
    10 months ago

    Hi conniedevina 

    You can create only one active relationship between two tables (if that doesn't result to an ambiguous relationship path with other tables) but you can have more inactive relationships. Inactive relationships can be invoked via measure using USERELATIONSHIP function

    The image below shows a single date column but returns different values depending on which inactive relationship is invoked.

    Please see the attached pbix.