Uploaded by Abdulazeez Abdullah Temitope

Demystifying DAX

advertisement
Demystifying DAX
TOPIC – Bi-directional relationships in PowerBI
Remember your data model is just a set of tables linked by a relationship. This relationship could
either be 1-*, 1-1, *-1 or *-* with each of these having either a unidirectional or bi-directional
cross filter. For a unidirectional cross filter, your dimension table filters the fact table and can’t be
otherwise while for bi-directional cross-filter, both tables can filter each. Here is an example of a
data model showing both cardinalities with a bi-directional relationship existing between the Sales
and Product tables.
*Cardinality is simply the direction of your relationship.
If the cardinality of all relationships in the model were unidirectional, Date, Product and Customer
tables will filter the Sales table. Date table cannot filter the customer nor product table likewise
otherwise. Say you are interested how many of your products was sold in a particular year, not the
number of times it was sold in that year. Just the list of products that was sold that year. Your guess
is as good as mine, I will just do a distinct count of the Product key on the Sales table right.
Below is an image of the result without the bi-directional cross-filter.
Because the filter direction is from Products to Sales table, the DAX measure returned a single
value of 2517 which is the total inventory in the store.
After enabling bi-directional cross filter
So, the question is why enable bi-directional filtering when I could get the same result without it.
My answer is what if your product table contains more information than just the product name and
product key and there is additional drill down you want to do.
Note that with a very good model, you can do without bi-directional but with complex DAX comes
complex wahala you didn’t sign up for. If your no. of products is based of the Products table, there
will be trouble as seen above where I had 2517 for all years.
With just the product key, I can see that as the year progresses, the no. of different products bought
increases which is a good thing. I’m not a champion of just a few products when there are over
2000 different products in my inventory. This increase could be attributed to better marketing,
discounted products etc. but that is not the topic of discussing.
Now I want drill down into how each product category is fairing yearly and this is where your
knowledge of the cardinality of your relationship come into place because a direct relationship
between the date and product table.
Use case – I want to see how which category of products were sold each and how many.
Because I’ve enabled the bidirectional filtering, I’ve indirectly created a relationship between the
product and calendar table.
Result below. Note that count of product key on sales table is a distinct count.
If I remove the bidirectional filtering, I got wrong figures. The same set of numbers each year.
HOW DOES IT WORK
* INSERTS VIDEO
Download