DAX Filter - USERELATIONSHIP function



Description

Specifies the relationship to be used in a specific calculation as the one that exists between columnName1 and columnName2.

Syntax

USERELATIONSHIP (<columnName1>, <columnName2>) 

Parameters

Sr.No. Parameter & Description
1

columnName1

A fully qualified name of a column that represents the many side of the relationship to be used.

If the parameters are given in a reverse order, the function will swap them before using them.

This parameter cannot be an expression.

2

columnName2

A fully qualified name of a column that represents one side or lookup side of the relationship to be used.

If the parameters are given in a reverse order, the function will swap them before using them.

This parameter cannot be an expression.

Return Value

DAX USERELATIONSHIP function does not return any value. The function only enables the indicated relationship for the duration of the calculation.

Remarks

  • USERELATIONSHIP can only be used in DAX functions that take a filter as a parameter. For example, CALCULATE, CALCULATETABLE, CLOSINGBALANCEMONTH, CLOSINGBALANCEQUARTER, CLOSINGBALANCEYEAR, OPENINGBALANCEMONTH, OPENINGBALANCEQUARTER, OPENINGBALANCEYEAR, TOTALMTD, TOTALQTD and TOTALYTD functions.

  • USERELATIONSHIP uses the existing relationships in the model, identifying relationships by their ending point columns.

  • In USERELATIONSHIP, the status of a relationship is not important; that is, whether the relationship is active or not does not affect the usage of the function. Even if the relationship is inactive, it will be used and overrides any other active relationships that might be present in the model but not mentioned in the function parameters.

  • An error is returned if any of the columns named as a parameter is not part of a relationship or the parameters belong to different relationships.

  • If multiple relationships are needed to join table A to table B in a calculation, each relationship must be indicated in a different USERELATIONSHIP function.

  • If CALCULATE expressions are nested, and more than one CALCULATE expression contains a USERELATIONSHIP function, then the innermost USERELATIONSHIP is the one that prevails in case of a conflict or ambiguity.

  • Up to 10 USERELATIONSHIP functions can be nested. However, your expression might have a deeper level of nesting.

Example

Product Sales:= CALCULATE ( 
   SUM (Sales[Sales Amount]), 
   USERELATIONSHIP (Sales[Product],Products[Product]) 
)
dax_functions_filter.htm
Advertisements