Search code examples
powerbidaxfilteringdatabase-schema

Avoiding bidirectional filter for a matrix report


I am learning how to use Power BI and one of the repeating pro tips is to avoid bidirectional filtering. I have a model with the following structure:

Table 1 (Course names):

  • Course ID
  • Course name

Sample data:

C1  Python
C2  Calculus
C3  Algebra

Table 2 (Course category):

  • Course Id
  • Course category

Sample data:

C1  CS
C2  Math
C3  Math

Table 3 (Course lecturers):

  • Lecturer name
  • Course Id

Sample data:

L1  C1
L2  C1
L1  C2
L3  C2
L3  C3

There may be multiple courses in a single category and multiple lecturers in a single course.

I would like to generate a matrix report where the rows are by lecturer name, the columns are by category, and the value is the distinctcount of courses. In other words, I would like to understand how many courses from each category each lecturer teaches. For the given sample data I would expect the following result:

    CS  Math
L1  1   1
L2  1   0
L3  0   2

The only way I got this working was to define the relationship between the tables as bidirectional. Is there an alternative schema that avoids this?


Solution

  • The advice is correct - avoid bi-directional filtering for numerous reasons. Where you need to propagate a relationship, you can turn on bi-directional filtering for a single measure as required using CROSSFILTER().

    https://learn.microsoft.com/en-us/dax/crossfilter-function