Forum Discussion

Clara's avatar
Clara
Icon for Advocate II rankAdvocate II
6 years ago
Solved

Using both primary (active) and secondary (inactive) relationship in a measure?

Hi all!   Here's my problem: I have two tables, and each of them have a Date and a Unit column. I've created a date table and successfully set up a relationship between the two tables through their...
  • Clara's avatar
    Clara
    6 years ago

    I have! I might have figured it out.

    I decided not to use SAMEPERIODLASTYEAR (though I'm not sure it has any part in making it work) and instead ended up with this measure:

     

    SalesTotal_LY =
    VAR LastYr = DATEADD(Calendar[MonthYear],-1,YEAR) RETURN CALCULATE(
    SUM(Table1[Sales]),
    USERELATIONSHIP(Table1[Units],Table2[Units]),
    Table1[MonthYear]=LastYr,
    FILTER(ALLEXCEPT(Table1,Table1[MonthYear]),
    Table1[Units]=[RelUnit]),
    Table1[ItemId]="001")

    [RelUnit] looks like this (I'm not even sure I need it, but haven't tried taking it out yet:

    RelUnit = CALCULATE(MIN(Table1[Units]),USERELATIONSHIP(Table1[Units],Table2[Units]))