Skip to main content

What is the Role-playing dimension?

Table of Contents

Role-playing dimensions are those dimension tables that are used more than once in a model to represent different roles or perspectives. This usually crops up in those fact tables that have multiple columns related to dates or other attributes in some way that corresponds to different times or contexts in which an event can occur.
For example, in a sales data model, you may want to analyze sales by order date, shipment date, and delivery date. In this case, the dimension “Date” would be used three times, each playing a different role— Order Date, Shipment Date, Delivery Date.
How to Implement Role-Playing Dimensions:
Create calculated tables: One way could be duplicating the dimension table and renaming it as per every role that you want to use. For example, by duplicating the table “Date,” you could make different tables for Order Date, Shipment Date, and Delivery Date. This can be done for Power Query; use the duplicate option and in DAX create new tables like Order Date = ‘Date’. Then, establish relationships between the new dimension tables and the fact table on the corresponding columns, and use them in your visuals.
Use the USERELATIONSHIP function: In your model, you can retain the inactive relationship and define the measures using the USERELATIONSHIP function to specify the context in which the calculation should apply the appropriate active relationship. This technique requires setting up several relationships from one table having a common relationship. For example, you could define a measure for Sales Amount by Sales Date or Delivery Date as follows, in DAX expression:

Copy code
Sales Amount by Sales Date = CALCULATE([Sales Amount], USERELATIONSHIP('Date'[Date], 'Sales'[Sales Date]))

It allows you to handle different roles of a dimension effectively within a single model.

Gross By Sales Date = CALCULATE(Sum(Sales[Gross Sales]), 
  USERELATIONSHIP(Sales[Sales Date], 'Date'[Date]))
Gross By Delivery Date = CALCULATE(Sum(Sales[Gross Sales]), 
  USERELATIONSHIP(Sales[Deilvery Date], 'Date'[Date]))

Use of userelationship is optional for active join.

HR Analytics Example.

Add comment