Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 61

Building a Semantic Model in Power BI

This lesson is built with resources from youtube.com, tabulareditor.com and 1 more site.

Hello! In our last lesson, we established the "why" and "what" of a semantic layer, understanding its role as a crucial abstraction that provides a single source of truth through metrics and dimensions. Today, we move from theory to practice.

This lesson directly addresses the learning outcome: Implement a basic semantic model for a business scenario in a BI tool. We will use Power BI to build a simple but effective model from the ground up. For you as an enterprise architect, this process will be familiar—it's about applying a specific design pattern (the star schema) to create a small, performant system for business analytics.

Let's get started.

1. The Blueprint: Understanding Facts and Dimensions

Before we start building, we need a blueprint. In data modeling for analytics, the most common and effective blueprint is the star schema. We touched upon its components—metrics and dimensions—in the last lesson. A star schema organizes your data into two types of tables:

  • Fact Tables: These tables contain the quantitative data about business events. They record what happened. They are typically "tall and narrow" (many rows, fewer columns). In our scenario, a Shipments table is a perfect example, recording the amount and quantity for each shipment event.
  • Dimension Tables: These tables contain the descriptive attributes that give context to the facts. They answer the "who, what,where, when" questions. They are typically "short and wide" (fewer rows, more columns). Tables like Products, Salespersons, and Locations are dimensions.

To see how these concepts come together, let's watch a video that introduces them using a practical example of a chocolate company.

Learn Data Modelling & Star Schema for Power BI in 20 minutes

The video 'Learn Data Modelling & Star Schema for Power BI in 20 minutes' by Chandoo provides an excellent conceptual foundation. This first segment will explain the difference between fact and dimension tables and how they form a star schema.

Please watch from the beginning to 08:59. Focus on understanding: The role of the 'shipments' table as a fact table. The role of tables like 'product', 'people', and 'calendar' as dimension tables. Why this structure is called a 'star schema'.

The key architectural principle here is the separation of concerns. The fact table is optimized for storing large volumes of numeric, measurable data, while the dimension tables store the descriptive, contextual information in a clean and non-redundant way.


2. Hands-On: Building the Model in Power BI

Now that we have the blueprint, let's implement it. We'll load the data into Power BI and establish the relationships that form the star schema. In the Power BI world, this is done in the Model View.

Relationships are the "wires" that connect our fact and dimension tables. They tell Power BI how to filter data across tables, allowing you to, for example, filter total sales (from the fact table) by a specific product category (from the dimension table).

Let's continue with the same video, which now demonstrates the practical steps.

Learn Data Modelling & Star Schema for Power BI in 20 minutes

This segment of the video shows you how to load data and create relationships in Power BI's Model View. It also explains the practical impact of these relationships on your visuals.

Watch from 08:59 to 21:33. Pay close attention to: Loading data from the tables into the Power BI model. Navigating to the Model View to see the tables and their relationships. Manually creating a relationship by dragging a key field from one table to another. The concepts of cardinality (the * and 1 symbols) and filter propagation (the arrow on the relationship line). The demonstration of what happens to a visual when a relationship is missing—this highlights why the model is so critical.

After completing these steps, you will have a functional star schema. Each line connecting a dimension to the central fact table represents a pathway for analysis.

Semantic Model in Power BI
This is an example of what a semantic model looks like in Power BI's Model view. The lines represent the relationships you've just created, connecting dimension tables (like 'Customers', 'Products') to a fact table (like 'Invoices').
Test your understanding!

In the video, the relationship between the Shipments table and the Products table is described as "many-to-one" (*:1).

In your own words, what does this mean in the context of the chocolate company's data? Why wouldn't it be "one-to-one" (1:1)?

Show answer

A "many-to-one" relationship from Shipments to Products means:

  • Each product in the Products table can be associated with many shipment records in the Shipments table. For example, the same "Milk Chocolate Bar" can be shipped thousands of times.
  • Each shipment record in the Shipments table can only be associated with one product in the Products table. A single shipment event is for a specific product.

It wouldn't be "one-to-one" because that would imply that each product is shipped only once, which is not how a sales business operates.


3. Defining Business Logic with Measures

You have now built the structure of the model. The final step in creating a basic semantic model is to explicitly define the business logic—the metrics we discussed in the last lesson.

In Power BI, this is done by writing measures using the DAX (Data Analysis Expressions) formula language. You might be tempted to just drag a numeric field like "Amount" into a chart and let Power BI sum it up for you. This is called an implicit measure. However, a robust semantic model relies on explicit measures.

Type How it's created Why it's used
Implicit Measure Dragging a numeric field into a visual. Power BI applies a simple aggregation (SUM, AVG, COUNT). Quick, ad-hoc analysis.
Explicit Measure Writing a DAX formula, e.g., Total Sales = SUM(Shipments[Amount]). The best practice. Creates a reusable, centrally defined piece of business logic. The definition of "Total Sales" is now stored in the model, ensuring everyone uses the same calculation.

Let's create one simple, explicit measure to define our primary metric: Total Amount.

To create your first measure:

  1. In the Report View of Power BI, right-click on the Shipments table in the Data pane on the right.
  2. Select New measure.
  3. The formula bar will appear at the top. Type the following DAX formula:
    Total Amount = SUM(Shipments[Amount])
  4. Press Enter.

You will now see a new field in your Shipments table with a calculator icon next to it. This is your explicit measure. Now, whenever anyone wants to analyze the total sales amount, they can use this single, governed Total Amount measure, fulfilling the "single source of truth" promise of a semantic layer.

While DAX can become very complex, even this simple step of defining your core metrics as explicit measures is a huge leap towards a robust and maintainable semantic model.


Conclusion

In this lesson, you have moved from architectural theory to hands-on implementation. You took raw data tables and structured them into a meaningful and powerful analytical model within Power BI.

Key Takeaways:

  • A semantic model in Power BI is built in the Model View by defining tables and the relationships between them.
  • The star schema is a best-practice design pattern, organizing tables into quantitative facts and descriptive dimensions.
  • Relationships have cardinality (e.g., many-to-one) and a filter direction, which control how data is aggregated and sliced in visuals.
  • Business logic is defined using explicit measures written in DAX. This ensures that key metrics are consistent, reusable, and governed, forming the core of your semantic layer.

In our next lesson, Apply data model optimization techniques (e.g., aggregation tables) to improve BI performance, we'll explore how to make the model you just built even faster and more efficient, especially as it scales to handle larger datasets.