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.
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:
Sales = SUM(FactInternetSales[SalesAmount])
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;
Filter Product =
However, using a measure like above normally is not necessary, because as you have seen the simple measure works like a charm.
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:
- What is a Relationship?
- What is the Cardinality of the Relationship?
- What is the Direction of the Relationship?
- Data preparation; First and Foremost Important task
- What is a Dimension table and why say No to a single big table
- Basics of Modeling in Power BI: Fact Tables
- Combining Dimension Tables in Power BI using Power Query; Foundation of Modeling in Power BI
Download Sample Power BI File
Download the sample Power BI report here: