Imagine that you own a supermarket in Ibadan. You keep different records about your business.
You have one table containing customer information, another table containing product information, and another table containing sales records.
These tables contain different information, but they are connected because they belong to the same supermarket.
How can you make Power BI understand that a particular customer bought a particular product?
The answer is data modelling and relationships.
In this module, you will learn how to connect tables in Power BI so that information from different tables can work together.
A data model is the structure that shows how different tables and their information are organised and connected.
Think about a school.
A school may have different tables containing:
These tables may contain information about the same students, teachers or classes.
A data model helps Power BI understand how the tables are connected.
| Students Table | Classes Table |
|---|---|
| Student ID: 101 | Class ID: 1 |
| Name: Ada | Class Name: JSS 1 |
| Class ID: 1 | Class ID: 2 |
| Name: John | Class Name: JSS 2 |
The Students table contains a Class ID. The Classes table also contains a Class ID.
Power BI can use these matching values to connect the two tables.
Imagine that a supermarket has 10,000 sales records. Each record contains information about a product sold.
Instead of typing the product name and price repeatedly in every sales record, the supermarket can keep product information in a separate table.
Power BI can connect the sales table to the products table.
Data models are useful because they help you:
A primary key is a column that uniquely identifies each record in a table.
For example, a school may have 500 students. Some students may have the same first name, but each student should have a unique Student ID.
Consider this table:
| Student ID | Student Name | Class |
|---|---|---|
| 101 | Ada | JSS 1 |
| 102 | John | JSS 2 |
| 103 | Ada | JSS 3 |
The Student ID column is the primary key because each student has a different ID.
Even though two students have the same name, their Student IDs are different.
A foreign key is a column in one table that refers to a key in another table.
Let's use our school example again.
| Class ID | Class Name |
|---|---|
| 1 | JSS 1 |
| 2 | JSS 2 |
| 3 | JSS 3 |
| Student ID | Student Name | Class ID |
|---|---|---|
| 101 | Ada | 1 |
| 102 | John | 2 |
| 103 | Mary | 1 |
In the Classes table, Class ID is the primary key.
In the Students table, Class ID is a foreign key because it refers to the Class ID in the Classes table.
This connection helps Power BI understand which class each student belongs to.
A relationship is a connection between two tables using related columns.
For example, a school may have a Students table and a Classes table.
Both tables contain a Class ID column. Power BI can use these columns to create a relationship.
When the relationship is created, Power BI can use information from both tables in the same report.
For example, you can create a report showing:
Power BI supports different types of relationships. The most common ones you should understand are one-to-many, one-to-one and many-to-many.
A one-to-many relationship means that one record in the first table can be connected to many records in the second table.
Example: One class can have many students.
| Class ID | Class Name |
|---|---|
| 1 | JSS 1 |
| 2 | JSS 2 |
| Student ID | Name | Class ID |
|---|---|---|
| 101 | Ada | 1 |
| 102 | John | 1 |
| 103 | Mary | 2 |
JSS 1 has two students in this example. JSS 2 has one student.
One class can be connected to many students.
This is called a one-to-many relationship.
A one-to-one relationship means that one record in the first table is connected to only one record in the second table, and vice versa.
Example: A school may keep student names in one table and additional student profile details in another table.
| Student ID | Name |
|---|---|
| 101 | Ada |
| 102 | John |
| Student ID | Emergency Contact |
|---|---|
| 101 | 08011111111 |
| 102 | 08022222222 |
Each student has one matching profile record in this example.
A many-to-many relationship means that many records in one table can be connected to many records in another table.
Example: Students and school clubs.
One student can join many clubs, and one club can have many students.
| Student ID | Student Name |
|---|---|
| 101 | Ada |
| 102 | John |
| Club ID | Club Name |
|---|---|
| 1 | Science Club |
| 2 | Press Club |
A student-club membership table can record which students belong to which clubs.
For example:
| Student ID | Club ID |
|---|---|
| 101 | 1 |
| 101 | 2 |
| 102 | 1 |
Ada belongs to both clubs, while John belongs to the Science Club.
This is a many-to-many situation. In a well-designed model, a separate membership table is commonly used to connect the two tables.
Model View is where you can see how tables are connected in Power BI Desktop.
It displays your tables as boxes. Lines between the boxes show relationships.
Each table box may show its column names.
You can use Model View to:
Let's create a relationship between a Students table and a Classes table.
Power BI should now display a line connecting the two tables.
When creating a relationship, Power BI provides settings that determine how the tables work together.
Cardinality describes how records in one table relate to records in another table.
Common options include:
Cross-filter direction determines how filters can travel between related tables.
Two common options are:
For a simple school model, a single direction from the Classes table to the Students table is often a good starting point.
A star schema is a common way of organising tables in a data model.
It has one central table called a fact table. Other tables, called dimension tables, connect to it.
The structure often looks like a star because several tables connect to the central table.
A supermarket may have these tables:
The Sales table is the central fact table. The other tables provide information that helps explain the sales records.
A fact table stores business activities or events that you want to analyse.
Examples include:
A dimension table stores descriptive information about the people, products, places or dates connected to the activities.
Examples include:
A fact table tells you what happened. A dimension table helps explain who, what, where or when it happened.
When creating relationships, beginners sometimes make mistakes that affect their reports.
Here are some common problems to avoid:
Always connect columns that represent the same kind of information.
For example, connect Student ID to Student ID, not Student ID to Student Name.
In a one-to-many relationship, the column on the one side must contain unique values.
If the Classes table contains Class ID 1 several times, Power BI may not be able to use it as the one side of that relationship.
The columns used for a relationship should have compatible data types.
For example, one Class ID column should not be stored as text while the matching column is stored as a number without appropriate conversion.
Check that the values in your related tables match correctly.
If a student has Class ID 5 but there is no Class ID 5 in the Classes table, that student may not match a class record.
Do not connect every table to every other table without a clear reason. A well-organised model is easier to understand and maintain.
You are working as a junior data analyst for a school in Ibadan. The school wants to analyse student information and examination results.
Create the following three tables in Excel.
| Student ID | Student Name | Class ID |
|---|---|---|
| 101 | Ada | 1 |
| 102 | John | 1 |
| 103 | Mary | 2 |
| 104 | David | 2 |
| 105 | Grace | 3 |
| Class ID | Class Name |
|---|---|
| 1 | JSS 1 |
| 2 | JSS 2 |
| 3 | JSS 3 |
| Result ID | Student ID | Subject | Score |
|---|---|---|---|
| 1 | 101 | Mathematics | 85 |
| 2 | 101 | English | 78 |
| 3 | 102 | Mathematics | 70 |
| 4 | 103 | Mathematics | 90 |
| 5 | 104 | English | 82 |
| 6 | 105 | Mathematics | 88 |
Create a table visual in Report View showing:
Use fields from all three tables. If the relationships are correct, Power BI should be able to display the related information together.
| Term | Meaning |
|---|---|
| Data Model | The structure showing how tables and information are organised and connected. |
| Relationship | A connection between tables using related columns. |
| Primary Key | A column that uniquely identifies each record in a table. |
| Foreign Key | A column that refers to a key in another table. |
| One-to-Many | One record in a table can be connected to many records in another table. |
| One-to-One | Each record in one table matches one record in another table. |
| Many-to-Many | Many records in one table can be connected to many records in another table. |
| Cardinality | The type of relationship between two tables. |
| Fact Table | A table containing events or activities to analyse. |
| Dimension Table | A table containing descriptive information about facts. |
| Star Schema | A data model with a central fact table connected to dimension tables. |
| Model View | The Power BI area used to view and manage table relationships. |
1. What is a data model?
2. What is a primary key?
3. What is a foreign key?
4. Which relationship allows one class to have many students?
5. What does a one-to-one relationship mean?
6. Which Power BI view is used to see relationships between tables?
7. What does cardinality describe?
8. What is a fact table?
9. What is a dimension table?
10. What is a star schema?
In this module, you learned how to organise and connect different tables in Power BI.
You discovered that:
You have completed Module 6 of Introduction to Power BI.
You now understand how different tables can work together to provide useful information.
In the next module, you will learn about DAX, which stands for Data Analysis Expressions.
You will discover:
Get ready to make Power BI perform calculations for you!