Skip to main content

Analyse Data by using Role-Playing Dimensions Effectively in Power BI

Role-playing dimensions are one of the key concepts in Data Warehousing and Business Intelligence development. If you are not familiar with it you can read James Serra's Blog article on Role-Playing Dimensions from here

In this article, I'm going to demonstrate to you How to Analyse Measures by using Role-Playing Dimensions Effective manner. If you are familiar with Relationships in Power BI you know by now, you cannot create two active relationships simultaneously with the same tables in a Power BI model. You must make one relationship Active while other relationship's inactive. 



For this Demo, I've taken the WideWorldImportersDW demo database. So you can download it from here for free. For simplicity, I only have taken the Sales and Date table and imported it into Power BI. 



You can see in this data model we have a Sales transaction fact table and Date dimension table. If you looked closely the Sales table contains two Date columns, Invoice Date and Delivery Date. But, in theory, we cannot have both relationships as active. This means only one relationship filter can apply in your report. In this case, I can only visualize the Sales data using the Invoice Date. Because it is the active relationship in this model. Even the relationship exists for the Delivery Date, since it is inactive we cannot use it for visualization. 

So, in this model, Date table working as a role-playing dimension. At a time it plays the Invoice Date role. In another time the role of the Delivery Date

In this model, I created a Calculated Measure for Quantity and named it as Invoiced Qty. Because, in the model, we have made Invoice Date as Active relationship. 

Invoiced Qty = SUM(Sale[Quantity])

At any given time the end-user can visualize the Quantity with Invoice Date as below. 



Then Why is an Inactive Relationship?

Though you cannot use inactive relationship filters straight away, you can use them Programmatically. This means Power BI allows us to create Calculations by making use of them. I'm going to create another Measure called Delivered Qty by referring the relationship Sales[Delivery Date] ---- Date[Date]



Delivered Qty = CALCULATE([Invoiced Qty], USERELATIONSHIP(Sale[Delivery Date Key], 'Date'[Date]) )

Let's visualize them both and see what are the differences. By looking at both visuals, at a glance you would not see much difference. But, in fact, there are references in figures. Because both measures calculating the Item Qty respective to Date.  



If you put both Measures and visualize, you may see a slight difference like this. 



Let's Improve the End-user Experience 

Now, we know how to use role-playing dimensions by creating DAX measures. What if we can make this more usable. How about a Slicer? If we can create a slicer or a Switch to toggle between and each role, this will be an awesome experience for the end-user. Here is how to do it. 

1. Create a Table by Entering Roles (Filter values) 

In this step, use the Enter Data feature to key the values you need to be a toggle in the visual. I'll make this table hide for report users. 

 
2. Create a calculated Measure to get the Selected filter value. I did not want to make my final Measure too complex. So I break it into small pieces. This is to make it more clear. You know what I mean 😉




Selected Role = SELECTEDVALUE('Date Role'[Analyzed By]) 
  
3. The final step, create a Calculated Measure for Quantity using the Selected Role measure we created in step 2. We need to show the Quantity value, either Invoiced Qty or Delivered Qty based on the selection. 

 







Total Qty = IF([Selected Role] = "Invoiced", [Invoiced Qty], [Delivered Qty])

Finally, you can give a rich analysis experience to the end-user by combining features offered by Power BI. 



Hope you learn how to analyze data with role-playing dimensions simultaniously. You can download the Power BI Demo pbix file from here

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. I feel Power BI is the most complex and useful tool to create the dashboards and produce reports for end users.

    Powerbi Read Rest

    ReplyDelete
  3. You finished certain solid focuses there. I did a pursuit regarding the matter and discovered almost all people will concur with your blog.

    360DigiTMG

    ReplyDelete
  4. There is plainly a ton to consider this. Keep working, remarkable work!
    360DigiTMG data science course

    ReplyDelete
  5. Set aside my effort to peruse all the remarks, however I truly delighted in the article. It's consistently pleasant when you can not exclusively be educated, yet in addition, engaged!
    difference between analysis and analytics

    ReplyDelete
  6. I will truly value the essayist's decision for picking this magnificent article fitting to my matter.Here is profound depiction about the article matter which helped me more.
    data science training in noida

    ReplyDelete
  7. Informative content. Thanks for sharing information.
    big data training london

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete

Post a Comment

Popular posts from this blog

Run T-SQL Script Files Using Command Line

Most of the time when we need to execute a SQL script or statement, then we go for SQL Server Management Studio to execute our T-SQL scripts. But the same result we can achieve using Command Prompt. This is very simple way to do that just a matter of write a command and pass few arguments. You can see the process status like as in when you execute a query in Management studio. Use-case : There may be having some situations you won't be able to execute T-SQL script using Management Studio. Most of the time when doing data population. In my case, I had a situation I needed to populate a Database without using backup/restore. Once I generated script with all the schemas and related data it took around 400+Mb sql file.  SQL Server Management Studio will not allow you to run the script unless you execute the query in high-end box. Because, when the file loaded to the memory it will too hard to cater our requirement. You may probably get  memory ...

How to Create a Date Table in Few Steps Using Power BI

Calendar Dimension or Calendar Table is one of the crucial table in a Power BI model. I never have seen any data warehouse data model which does not have a Calendar table so far in my development. Because, when it comes to data warehousing or dimension modeling you may storing various business processes or events as Facts. So those events anyway occur in particular date or time. So simply there wouldn’t be a Power BI data model without a date table. In this post, I’m going to share with you how to create a date table within few steps. Actually, there are two DAX measures which we can use to create a date table. Calendar(DAX) and CalendarAuto(Auto). Calendar(DAX) = You can pass start date and End date as parameters you need to create date table. CalendarAuto(DAX) = You can use this function without passing any parameter. Then it will generate the dates based on your data model dates.  You can simply copy the below DAX code and paste in your Power BI Desktop DAX e...

Forecast Financial Data Using MS Excel 2016

With the New release of Excel 2016  Microsoft has provided handy way to do the forecasting using the user data. Within few clicks you will be able to do the forecasting without knowing the thorough knowledge about the Data Mining or Predictive Analytics. Just to have some domain knowledge about the data you are going to play around will be enough. From this blog post I will be showing a sample data forecast analysis I've done using MS Excel 2016 Forecast Feature. 1. Created a Test Data Set for do the prediction. I used vTimeSeries   view in AdventureWorksDW2014 sample database. (This view returns the Time Series  data Sales data which change over the time. This can be useful to do the Financial forecast on sales data) 2. In this view return the sales amount correspond to the reporting date. I've made a small change to the query in-order to improve the readability. I sort the data-set using reporting date. 3. Open Microsoft Excel 2016 and Create a N...