Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Relationship between USERELATIONSHIP and filters

Hi all, I have a list of all applications as my main data source. The PROCESSED date is linked to DATE in a separate calendar file. I also have an inactive secondary relationship between RECEIVED an...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi,

    This has been solved, but not in a way I particularly like. It comes down to the relationship between FILTER and USERELATIONSHIP and I don't fully understand it.


    The "standard" series uses FILTER to choose from 3 ORs. I.e:

     

    m4 - Total Number CH and AP and TR
    =CALCULATE(
    [m1 - Total Number Change and RMA],
    FILTER('Model',[IDFirst2Chrs]="CH" || [IDLast2Chrs]="AP" || [IDFirst2Chrs]="TR"
    )
    )

     

    When this is combined with USERELATIONSHIP, the code is:

     

    =CALCULATE(
    [m4 - Total Number CH and AP and TR],
    USERELATIONSHIP('Model'[Lodge Date.DDMMYYYY],Calendar2[Date])
    )

     

    This does not return correct results for months, but does return correct for the overall relationship.

    My hypothesis was that the multiple FILTERS were the problem (M1R, which did not use FILTER, worked perfectly).

    As such, I created a helper column in the Data model that emulated the FILTER function:

     

    [TR CH AP Type]
    =IF([IDLast2Chrs]="AP",1,IF([IDFirst2Chrs]="TR",1,IF([IDFirst2Chrs]="CH",1,0)))

     

    I then recreated my core measure using this as a native filter rather than using FILTER:

     

    m4a - Helper Column
    =CALCULATE(
    [m1 - Total Number Change and RMA],
    'Model'[TR CH AP Type]=1
    )

     

    I then combined this with USERELATIONSHIP:

     

    =CALCULATE(
    [m4a - Helper Column],
    USERELATIONSHIP('Model'[Lodge Date.DDMMYYYY],Calendar2[Date])
    )

     

    The result was that this new measure returned the correct results for the entire period AND individual months:

     

    m4R - Total Number CH and AP and TR Received2209195182287
    m4ar10578104287

     

    I assume it is due to the execution of the FILTER and USERELATIONSHIP functions and their relative sequencing.