Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Power Query Cookbook Use effective and powerful queries in Power BI Desktop and Dataflows to prepare and transform your data (Janicijevic, Andrea) (z-lib.org).pdf
Скачиваний:
143
Добавлен:
14.08.2022
Размер:
25.9 Mб
Скачать

150 Combining Queries for Efficiency

Technical requirements

For this chapter, you will be using Power BI Desktop (https://www.microsoft. com/en-us/download/details.aspx?id=58494).

The minimum requirements for installation are listed here:

.NET Framework 4.6 (Gateway release August 2019 and earlier)

.NET Framework 4.7.2 (Gateway release September 2019 and later)

A 64-bit version of Windows 8 or a 64-bit version of Windows Server 2012 R2 with current Transport Layer Security (TLS) 1.2 and cipher suites

4 gigabytes (GB) disk space for performance monitoring logs

You can find the data resources referred to in this chapter at https://github.com/ PacktPublishing/Power-Query-Cookbook/tree/main/Chapter05.

Merging queries

Users usually need to merge data horizontally and enrich a table with additional columns that are not available within the main query when it is loaded from a data source.

In this recipe, you will see how to perform this merging and which steps to consider in order to get a successful result.

Getting ready

For this recipe, you need to download the following files:

FactInternetSales CSV file

DimTerritory CSV file

In this example, we will refer to the C:\Data folder.

Merging queries 151

How to do it…

Once you open your Power BI Desktop application, you are ready to perform the following steps:

1.Click on Get Data and select the Text/CSV connector.

2.Browse to your local folder where you downloaded the FactInternetSales CSV file and open it. The following window with a preview of the data will pop up; click on Transform Data:

Figure 5.1 – CSV data preview

152Combining Queries for Efficiency

3.Repeat these steps for the DimTerritory CSV file in order to end up with two queries in the Power Query user interface (UI)—FactInternetSales and

DimTerritory:

Figure 5.2 – Power Query UI

4.In this case, we want to enrich the FactInternetSales table with some columns coming from the DimTerritory table in order to get details of the geographical location of sales transactions. For this, you need to browse to the end of the Home tab and click on Combine and then Merge Queries:

Figure 5.3 – Merge Queries button

Merging queries 153

5.A Merge window will pop up. Select the SalesTerritoryKey column and select the DimTerritory table from the drop-down menu, as shown in the following screenshot:

Figure 5.4 – Merge window

154Combining Queries for Efficiency

6.In the second table, select the SalesTerritoryKey column. Select Left Outer (all from first, matching from second) for the Join Kind field. Leave the other options as they are and click on OK:

Figure 5.5 – Merge window columns selected

7.After you click OK, you will see that a new column will be added to the

FactInternetSales query:

Figure 5.6 – New column added

Merging queries 155

8.Click on the Expand icon on the right of the DimTerritory column, select

SalesTerritoryRegion and SalesTerritoryCountry, and click on OK:

Figure 5.7 – New columns selection

9.You will see two new columns coming from the other query (DimTerritory), matching the rows of the main table:

Figure 5.8 – Expanded columns