The Many-to-Many Relationship and its Many Problems Part 2

DOFEM (Oluwadamisi Olujobi)
4 min readAug 1, 2024

--

How to Avoid and Solve these Problems

Cardinality serves as the framework for how your tables interact in data analysis. It is crucial because incorrect relationships can make analysis difficult and in the worst-case scenario, produce inaccurate results. In the last blog, we explored the problematic scenarios that may arise from creating many-to-many relationships between your fact tables and discussed temporary solutions. Now we will look at a more effective solution to avoid these problems altogether.

Our Model

The image above shows the model and the relationships between the tables. Our goal is to include the Budget table in the model without creating a many-to-many relationship or complicating the model. The rule of thumb is to avoid creating relationships between fact tables. But how do we include the Budget table without facing many-to-many relationship issues?

Creating a Bridge Table

A more effective way to avoid many-to-many cardinality is by creating a bridge table. A bridge table helps connect two tables without linking them directly. The bridge table contains fields that reference a common field in Table A and Table B, allowing each record in the bridge table to link one record from Table A to one record from Table B. In our model, we need the bridge table to have a common field between the Sales and Budget tables.

We see that both the Sales and Budget tables contain date-related information. Therefore, we can create a Calendar table as a bridge table.

Creating a Calendar Table

We can create a Calendar table using the CALENDARAUTO() function in Power BI. To create the table, go to the Data view, and in the “Table Tools” tab, select “New Table.”

Creating a Calendar Table

The CALENDARAUTO() function creates a table with a single column of dates. It scans all the date columns in your dataset and determines the earliest and latest dates, generating a date table that includes every date from the earliest to the latest date found in the dataset.

A Calendar Table

After creating the Calendar table, it needs to be marked as a date table. This step is essential for ensuring accurate time intelligence calculations and efficient data analysis.

You will also notice an icon in front of the date column indicating that the table has been marked as a date table.

The Bridge Table in the Model

The Calendar table acts as a bridge table linking the Budget table and the Sales table. It does this by using the “Date” from the Calendar table to link to the “Order Date” in the Sales table and the “Date” in the Budget table. The bridge table contains fields that reference the relevant fields in both the Sales and Budget tables, allowing these tables to be connected indirectly through the Calendar table. This indirect connection via the Calendar table allows for accurate and efficient analysis without the complications of a direct many-to-many relationship.

--

--

DOFEM (Oluwadamisi Olujobi)

Welcome to DOFEM! Join me to dive into data analysis with Excel and Power BI. It goes beyond skills; it's about turning raw data into meaningful insights.