One Dimension Filters Another Dimension in Power BI

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail
FacebooktwitterlinkedinrssyoutubeFacebooktwitterlinkedinrssyoutube

I often get this question after I explain about the star-schema. The question is that both my dimensions are filtering my fact table values, but how can I get one dimension filtering another dimension? for example, how can I get only the list of products that have been purchased by this customer? In this article, I’ll explain how you can do that with the star-schema.

Sample dataset

The sample dataset for this example has only three tables below: (download the Power BI file at the end of the article)

DimCustomer and DimProduct both have one-to-many single directional relationship to the FactInternetSales. This is a simple star-schema model.

We also have a report like below;

In the report above, with selection of the FullName (from the DimCustomer table) slicer, or Color (from the DimProduct table), the table visual gets filtered. But what about other scenarios?

Only showing Products that this customer purchased

What if your requirement is to filter the Color slicer based on only products that the selected customer have purchased? In the above report, the Product slicer doesn’t get filtered by selection of the Customer slicer.

Why Filtering Doesn’t Happen Automatically?

You may ask why the product slicer doesn’t get filtered? The reason is that the direction of the relationship is from the Product table to the Fact table, which means only the product table can filter the fact table’s data, not the other way around. I have written a full article explaining the direction of the relationship and I recommend you to read it here.

This is normally the case that in a star-schema, the fact table is in the middle, and gets filtered by all dimensions, but dimensions can’t filter each other.

How to Filter One Dimension By Another?

If you have this requirement that one dimension should get filtered by another dimension, there are two ways to implement it. One is to use both-directional relationship (which I don’t recommend). Another is to use Measures for filtering.

Why not both-directional relationship?

Both-directional relationship comes with two major problems. The first problem is the significant performance impact of this. The second problem is that you cannot apply both-directional relationship all the time, it brings circular reference and ambiguity to your data model.

Using a Filter Measure

Another option is to use measures as a filter, which is what I called here as Filter Measures. You can create a measure like this:

This is a very simple measure that calculates the sum of the SalesAmount from the fact table.

You can use this measure in the Product slicer (Color slicer) as a visual level filter and set the value to be greater than zero. This means that only show Product Colors that there are sales for them based on the current selection of other slicers in the report.

This means that now the Customer slicer can filter the product slicer, without having the both-directional relationship in the data model.

You can use this measure also to filter the customer slicer based on the product slicer if you want it the other way around.

This method is not just for slicers, it can work for any other visuals too.

If a simple expression like above doesn’t work, you can take one step further and create a measure using CrossFilter function such as below;

However, using a measure like above normally is not necessary, because as you have seen the simple measure works like a charm.

Summary

So in summary, the simple trick is to create a measure that calculates a value from the fact table. Then use that measure as the visual level filter of the visual, and set the filter to be greater than zero (or what is the threshold of having an activity in the fact table).

If you haven't read other parts of Back to Basics Series of Power BI Modeling, here they are:

Download Sample Power BI File

Download the sample Power BI report here:

Enter Your Email to download the file (required)

Video

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail
FacebooktwitterlinkedinrssyoutubeFacebooktwitterlinkedinrssyoutube
Reza Rad on FacebookReza Rad on LinkedinReza Rad on TwitterReza Rad on Youtube
Reza Rad
Trainer, Consultant, Mentor
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for nine continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.
He wrote some books on MS SQL BI and also is writing some others, He was also an active member on online technical forums such as MSDN and Experts-Exchange, and was a moderator of MSDN SQL Server forums, and is an MCP, MCSE, and MCITP of BI. He is the leader of the New Zealand Business Intelligence users group. He is also the author of very popular book Power BI from Rookie to Rock Star, which is free with more than 1700 pages of content and the Power BI Pro Architecture published by Apress.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.

2 thoughts on “One Dimension Filters Another Dimension in Power BI

    • if you want the values in the table to be filtered, then you need to use a measure for customer names, using the field will work as a slice and dice, where using a measure would act as a value
      if you have a sales measure or a measure from the fact table, however, this works just fine. in the example in this post, it works as you said.
      Cheers
      Reza

Leave a Reply

%d bloggers like this: