Microsoft Power BI Complete Reference
上QQ阅读APP看书,第一时间看更新

Creating a new relationship 

In the previous section, you saw how to verify existing relationships, and even how to edit them. In this section, you are going to learn how to create a new relationship. There are six tables in the data model so far, and Power BI created a relationship for all the tables, except for two. Let's start by creating a relationship to the DimDate table.

The FactInternetSales table stores three different dates: OrderDate, ShipDate, and DueDate. There can be only one active relationship between two tables in Power BI, and all filtering occurs through the active relationship. In other words, which date do you want to see your total sales, profit, and profit margin calculations on? If it's OrderDate, then your relationship will be on the OrderDate column from the FactInternetSales table to the FullDateAlternateKey column in the DimDate table. To create a new relationship, open "manage relationships" from the home ribbon. 

Now, let's create a relationship from the OrderDate column in FactInternetSales to the FullDateAlternateKey column in DimDate. With the manage relationship editor open, click on New... to create a new relationship:

Figure 7- Creating a new relationship

Complete the following steps to create a new relationship:

  1. Select FactInternetSales from the list of tables in the dropdown
  2. Select OrderDate from the list of columns, and use the scroll bar to scroll all the way to the right
  3. Select DimDate from the next in the drop-down list
  4. Select FullDateAlternateKey from the list of columns
  1. The cardinality, cross filter direction, and whether the relationship is active or inactive is updated automatically by Power BI; remember to always verify these items.
  2. Click OK to close the editor

Congratulations, you have created your first relationship with Power BI!