Understanding the Query Editor Environment

Một phần của tài liệu Applied microsoft power bi Bring your data to life (Trang 196 - 199)

6.1 Understanding the Query Editor

6.1.1 Understanding the Query Editor Environment

Before I dive into the Query Editor’s plethora of features, let’s take a moment to explore its environment. As I mentioned, you launch the Query Editor when you click the Edit Queries button in the Power BI Desktop ribbon’s Home tab. The Query Editor opens in a new window, side by side with the Power BI Desktop main window. Figure 6.1 shows the main elements of Query Editor when you open it in the Adventure Works model that you implemented in the previous chapter.

Understanding the ribbon’s Home tab

The Home tab in the ribbon (see item 1 in Figure 6.1) includes buttons for common tasks and some frequently used columns and table-level transformations. Starting from the left, you’re already familiar with the Close & Apply button. When expanded, this button has three values, giving you options to close the Query Editor without applying the query changes to the data model (Close menu), to apply the changes without closing the editor (Apply), and both (Close & Apply). If you choose to close the editor without applying the changes, Power BI Desktop will display a warning that pending query changes aren’t applied.

NOTE Some structural changes, such as adding a new column, will reload the data in the corresponding table in the data model. Other changes, such as renaming columns, are handled internally without data refresh. Power BI Desktop (more accurately the xVelocity engine) always tries to apply the minimum steps for a consistent model without unnecessary data refreshes.

Figure 6.1 The Query Editor opens in a new window to give you access to the queries defined in the model.

The New Query ribbon group is another starting point for creating new queries if you prefer to do so while you’re in the Query Editor as opposed to Power BI Desktop. The Properties button opens a Query Properties window (Figure 6.2) that allows you change the query name (another way to change the query name is to use the Query Settings pane).

Sometimes, you might not want to load the query data in the data model, such as when you plan to append the query results to another query. If you don’t want the query to generate a table in the data model, uncheck the “Unable load to report” checkbox. And, if you don’t want to refresh the query results when the user initiates Power BI Desktop table refresh, uncheck “Enable refresh of this query”. Continuing on the list of Home tab’s buttons, the Advanced Editor button gives you access to the query source.

NOTE Queries are described in a formula language (informally known as “M”). Every time you apply a new

transformation, the Query Editor creates a formula and adds a line to the query source. For more information about the

query formula language, read “Microsoft Power Query for Excel Formula Language Specification” at http://go.microsoft.com/fwlink/p/?linkid=320633.

Figure 6.2 Use the Query Properties pane to change the query name, to enable data load to report, and to enable data refresh.

The rest of the buttons on the Home tab let you perform common transformations, including removing columns, reducing rows, grouping by and replacing values, and combining queries. We’ll practice many of these in the lab exercise that follows.

Understanding the ribbon’s Transform tab

The Transform tab (see Figure 6.3) includes additional table and column transformations.

Many of the column-level transformations from the context menu (see item 5 in Figure 6.1) are available when you right-click a column in the data preview pane. And, many of the table-level transformations are available when you expand or right-click the Table icon ( ) in the top-left corner of the data preview pane.

Figure 6.3 The Transform ribbon (split in the screenshot to reduce space) includes many table and column transformations.

Some transformations apply to columns that have specific data types (see the second row in Figure 6.3). For example, the Split Column transformation applies only to text

columns, while the Rounding transformation applies only to number columns.

Understanding the ribbon’s Add Column tab

The Add Column tab (see Figure 6.4) lets you create custom columns. For example, I’ll show you later how you can create a custom column that returns the end of the month from a given date column.

Figure 6.4 Use the Add Column tab in the ribbon to create custom columns.

NOTE Don’t confuse query custom columns with data model calculated columns. Added to the query, query custom columns are created using the Power Query formula language called “M” and they can’t reference fields in the data model. On the other hand, calculated columns in the data model are described in DAX and they can reference other fields in the model.

Understanding the ribbon’s View tab

The Query Settings button in the View tab toggles the visibility of the Query Settings pane

(item 3 in Figure 6.2). The Advanced Editor button does the same thing as the button with the same name (also called Advanced Editor) in the Home tab. It shows the source code of the query and allows you to change it. The Formula Bar checkbox toggles the visibility of the formula bar that shows you the “M” formula behind the selected transformation step.

Figure 6.5 The View tab gives you access to the query source.

So what does this “M” query language do for you anyway? It allows you to implement more advanced data manipulation. For example, Martin needs to load multiple Excel files from a given folder. Looping through files isn’t an out-of-box feature. However, once Martin applies the necessary transformations to a single file, he can use the Advanced Editor to modify the query source to define a query function. Now Martin can automate the process by invoking the query function for each file, passing the file path. I’ll show you some of these capabilities later in this chapter.

Một phần của tài liệu Applied microsoft power bi Bring your data to life (Trang 196 - 199)

Tải bản đầy đủ (PDF)

(447 trang)