Power BI Modelling
By: Peter Hui
Tags: Data Analysis, Data Science, Data Analytics, Machine Learning, Power Bi

This is my question,

I want to report on my inventory and transactions by day. Each day has sales so I want to know my sales.

Here we can already tell we want to report on inventory and sales. These will likely be our fact tables. It sounds like there is a date time dimension involved so we probably need a day time table.

These are our fact tables we want to use,

Image by author

We will also need a table to join the inventory and transactions table together, so we can filter by the dates. We will need a date table. Here we can use

Date_Filter = CALENDAR( DATE(2021,04,01), DATE(2021,12,31))

Power BI will automatically create a table for you. The result will be a table like this.

Simple date table — image by author

Here in this model, you can see that I will join the date table with the transactions date and inventory date.

Image by author

This is a basic model you need to remember.

Here the date table joins the inventory and sales table on the date columns. If you are to filter on date, it will “grab” the data from both tables. The Date table filters both the Inventory and Transactions table in a 1:Many relationship.

Now let’s expand this a little bit further and say,

I want to see the inventory and sales by type and who bought them.

Here we can tell that we will probably need something to filter again, both tables by the inventory and sales. We have the date dimension, but here the request is just by type. I will have to create a table that takes the unique product types of both tables in order to filter them all.

Here you can use Power Query to select the individual columns of the product types in the inventory and transactions table, append them and run a remove duplicate to create a filtering table.

In DAX, you can use DISTINCT to create a table that contains the unique values of all the inventories.

Product_Type_Filter = DISTINCT(Inventory[Inventory]))

This is how the model now looks, 🍦 🍩🍰

Image by author

Here I can filter by Date, by the product type and see only the customers that bought them.

Image by author

Once again, it’s a simple filter that allows you to filter through both tables to get at an answer.

It’s also important to talk a little about the filtering direction. Let’s look at this model again, I’ve added in the arrows.

Image by author

What do these arrows mean?

It means that when a user filters using the date filter or the product filter, and because these filtering tables are joined to the Inventory and Transactions tables, they will be able to filter them in one direction.

It’s important to filter on the same direction as the join.

Here, I have filtered on cake in the inventory table, which is not designed as a filtering table, and it will pull up a transaction of ice cream in the transactions table. As you can see, it can get very confusing quickly if you don’t use the proper filters.

image by author

I hope with this article you get the basics of creating a data model.

Remember this. The model you build doesn’t have to be hard. It just has to be simple and works. For it to work, it has to be something you and others can understand quickly.

No one will care how elegant your model looks if you can’t produce a report that was requested.

To recap,

Analyze your questions Identify your fact tables Creating filtering tables to join them

Take a look at the star set up.

Image by author

Isn’t this quite similar to what we have discussed? This is the famous star schema data model set up.

Now if you know a data modeler talking about star schema and snowflake, go ahead and ask them where the filtering tables and fact tables. They should be able to tell you right away.

If not, then it’s likely there is something wrong and I hope you won’t have to be the person to use the model or better yet, to rebuild it!