DAX Function Guide

USERELATIONSHIP
Empty image or helper icon

Sam McKay

CEO & Founder

How does the USERELATIONSHIP work?
The USERELATIONSHIP function (DAX) specifies the relationship to be used in a specific calculation as the one that exists between columnName1 and columnName2.
USERELATIONSHIP Formula Syntax

USERELATIONSHIP(
     <columnName1>,<columnName2>
)

How do you use the USERELATIONSHIP?

The USERELATIONSHIP function to apply an inactive relationship to a particular DAX expression. Its usage is simple in a measure, but one might consider alternative syntax in calculated columns.

The USERELATIONSHIP can only be used in functions that take a filter as an argument, for example: CALCULATE, CALCULATETABLE, CLOSINGBALANCEMONTH, CLOSINGBALANCEQUARTER, CLOSINGBALANCEYEAR, OPENINGBALANCEMONTH, OPENINGBALANCEQUARTER, OPENINGBALANCEYEAR, TOTALMTD, TOTALQTD and TOTALYTD functions.

Related Blog Posts

Loading

Considerations when using the USERELATIONSHIP?
  • USERELATIONSHIP cannot be used when row level security is defined for the table in which the measure is included. For example, CALCULATE(SUM([SalesAmount]), USERELATIONSHIP(FactInternetSales[CustomerKey], DimCustomer[CustomerKey])) will return an error if row level security is defined for DimCustomer.
  • USERELATIONSHIP uses 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 arguments.
  • An error is returned if any of the columns named as an argument is not part of a relationship or the arguments 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, ie. the following sample expression is nested 3 levels deep but only 2 for USEREALTIONSHIP: =CALCULATE(CALCULATE( CALCULATE( <anyExpression>, USERELATIONSHIP( t1[colA], t2[colB])), t99[colZ]=999), USERELATIONSHIP( t1[colA], t2[colA])).
Related Video Tutorials

Loading

Formula examples using the USERELATIONSHIP

=CALCULATE(SUM(InternetSales[SalesAmount]), USERELATIONSHIP(InternetSales[ShippingDate], DateTime[Date]))

= CALCULATE ( SUM (Sales[Sales Amount]), USERELATIONSHIP (Sales[Product],Products[Product])

= CALCULATE ( CALCULATE ( VALUES ( DimDate[EnglishDayNameOfWeek] ), FactInternetSales ), USERELATIONSHIP ( DimDate[DateKey], FactInternetSales[DueDateKey] ), ALL ( DimDate ) )

Related Courses

Loading