Accessing Power Query in Power BI
Power Query is accessible inside the Power BI Desktop tool by connecting to a data source and then clicking Transform Data (rather than Load or Cancel). For existing data models, Power Query can be accessed by right-clicking on the query in the Fields pane and clicking Edit query.
The Power Query window provides a ribbon at the top with tabs for Home, Transform, Add Column, View, Tools, and Help. There is also a Query Settings pane on the right-hand side that shows the name of the query and the steps applied to the data that get built up as you transform the data. The Applied Steps pane makes it easy to undo or redo different transforms and immediately see the impact of those transforms on the data, which is shown in the center of the window. The last part of the user interface is the Queries pane on the left-hand side of the window. This shows all queries that make up the data model and allows you to flip back and forth between them as you’re transforming and shaping data in your data model.
Unless stated otherwise, all data transformation capabilities discussed in this chapter will happen in Power Query. Let’s start with sorting and filtering data after we’ve connected to it.
Sorting and filtering
Sorting data is a key capability that helps us understand more about the data. When data is displayed in Power Query, it is shown in tabular format with rows and columns and sorting is easily accomplished by clicking the ▼ button on the column you want to sort on. From there, you can select Sort Ascending or Sort Descending. When this happens, a step gets added to the Applied Steps pane and you can instantly see the data sorted in the center of the window. Sorting can also be achieved by clicking the name of the column and then clicking the appropriate button under the Home ribbon under Sort.
To filter data in a column, you also use the ▼ button on the column you want to filter on and you see some options for Remove Empty and data type-specific filtering. The data type filtering options are shown in the following table:
Figure 4.1 – Filtering options by data type
A core capability of working with tabular data as we have in Power Query is managing the columns and rows of data. In the next section, we’ll explore how we can manage columns.