Forum Discussion

jsh121988's avatar
jsh121988
Icon for Microsoft Employee rankMicrosoft Employee
8 years ago
Solved

Deactivate Relationship in a measure

Hello,   I would like to perform the opposite of USERELATIONSHIP, in that I want to turn off a relationship for a particular measure. If possible, I would rather leave the active relationship, inst...
  • OwenAuger's avatar
    OwenAuger
    8 years ago

    Thanks for the info :)
    To ensure the measure is evaluated exactly as if the relationship doesn't exist, you should wrap your existing code in an outer CALCULATE with CROSSFILTER, something like below.

     

    This ensures that all filter arguments in your existing CALCULATE are evaluated with the relationship disabled, and in particular the FILTER( AH, ... ) code is not subject to the physical relationship.

     

    Does this give the expected result?

     

    Regards,

    Owen

     

     

    _dmRollingAboveHours =
    CALCULATE (
        CALCULATE (
            SUMX (
                ADDCOLUMNS (
                    AH,
                    "hours", DATEDIFF (
                        MAX (
                            [ChangedDate]
                                + ( HourLimit[HourLimit Value] / 24 ),
                            MIN ( _dtDateFilter[Date filter] )
                        ),
                        MIN ( [NextChangedDate], MIN ( _dtDateFilter[Date filter] ) + 1 ),
                        SECOND
                    )
                        / 60
                        / 60
                ),
                [hours]
            ),
            FILTER (
                AH,
                AH[ChangedDate]
                    + ( HourLimit[HourLimit Value] / 24 )
                    < MIN ( _dtDateFilter[Date filter] ) + 1
                    && AH[NextChangedDate] >= MIN ( _dtDateFilter[Date filter] )
                    && AH[Duration_h] >= HourLimit[HourLimit Value]
            )
        ),
        CROSSFILTER ( AH[NextChangedDate], _dtDateFilter[Date filter], NONE )
    )