Power Query
Power Query
Power Query is a business intelligence tool available in Excel that allows you to
import data from many different sources and then clean, transform and reshape
your data as needed.
It allows you to set up a query once and then reuse it with a simple refresh. It’s
also pretty powerful. Power Query can import and clean millions of rows into
the data model for analysis after. The user interface is intuitive and well laid out
so it’s really easy to pick up. It’s an incredibly short learning curve when
compared to other Excel tools like formulas or VBA.
The best part about it, is you don’t need to learn or use any code to do any of it.
The power query editor records all your transformations step by step and
converts them into the M code for you, similar to how the Macro recorder with
VBA.
In this phase, users connect to the data source(s) from which they want to extract
data. Power Query supports many data sources, including databases, files, web pages,
and more. Users can also specify any required authentication or authorization details
during this phase.
2. Transform
Once the data is loaded into Power Query, users can use various data transformation
tools to clean, reshape, and transform the data to meet their specific needs. Common
data transformation tasks include removing duplicates, filtering data, merging data,
splitting columns, and pivoting data.
3. Combine
Power Query also allows users to combine data from multiple sources using various
techniques. Users can merge tables, append, or join data using a common key. This
phase is beneficial for integrating data from different sources into a single, unified
view.
4. Load
Finally, in the Load phase, users specify where to load the transformed data. They can
load the data into an Excel worksheet or a Power BI report or create a connection to
the data source so that the data is automatically refreshed whenever the source data
changes.
The Query Editor
Power Query Editor is where any data transforma on steps will be created or
edited. There are 6 main area in the editor to become familiar with.
1. The Ribbon – The user interface for the editor is quite similar to Excel
and uses a visual ribbon style command center. It organizes data
transformation commands and other power query options into 5 main
tabs.
2. Query List – This area lists all the queries in the current workbook. You
can navigate to any query from this area to begin editing it.
3. Data Preview – This area is where you will see a preview of the data
with all the transformation steps currently applied. You can also access a
lot of the transformation commands here either from the filter icons in
the column headings or with a right click on the column heading.
4. Formula Bar – This is where you can see and edit the M code of the
current transformation step. Each transformation you make on your data
is recorded and appears as a step in the applied steps area.
5. Properties – This is where you can name your query. When you close
and load the query to an Excel table, power query will create a table with
the same name as its source query if the table name isn’t already taken.
The query name is also how the M code will reference this query if we
need to query it in another query.
6. Applied Steps – This area is a chronological list of all the transformation
steps that have been applied to the data. You can move through the steps
here and view the changes in the data preview area. You can also delete,
modify or reorder any steps in the query here.
In this section, let’s look at various transformation functions that can be performed
easily with the help of a few mouse clicks.
UPPERCASE
LOWERCASE
TRIM
Power Query has two different options that help us combine different datasets. The
two options are:
Append
Merge
APPEND
In Power Query, the append operation creates a new table by joining all the rows from
the first query, followed by all rows from the second query.
MERGE
The Merge option is similar to the JOIN function in SQL. Merge is a way of combining
two existing queries and creating a new query.
The Transform tab in Power Query houses an array of data transformation features. It
enables you to perform essential operations like changing data types, replacing
values, aggregating data, pivoting columns, and merging queries. This tab also offers
advanced transformation capabilities, such as applying conditional logic, invoking
custom functions, unpivoting data, and splitting columns based on delimiters. The
Transform tab empowers you to cleanse and reshape your data, ensuring it is in the
desired format for further analysis.
The File Tab:
The File tab in Power Query provides options for managing queries and connections
at the workbook level. From this tab, you can create new queries, import data from
external sources, export queries to other workbooks, or load queries from a query
repository. Additionally, the File tab allows you to access the Options menu, where you
can configure various Power Query settings, such as privacy levels, global query
settings, and regional preferences. The File tab serves as a gateway to essential file
and configuration-related functionalities in Power Query.
The Home tab in Power Query is the central hub for common data manipulation tasks.
It offers a set of frequently used operations, including filtering, sorting, grouping,
removing columns, and transforming data types. This tab also provides options to
manage query settings, such as refreshing queries, viewing query dependencies, and
accessing query properties. The Home tab serves as a convenient starting point for
most data transformation activities, allowing you to quickly perform common tasks
and navigate to other sections of Power Query.
The Add Column tab in Power Query is dedicated to enhancing your data by creating
new calculated columns. It offers a variety of functions, operators, and formulas that
you can use to define custom calculations based on existing data. From basic
arithmetic operations to advanced text manipulation, date calculations, and
conditional logic, the Add Column tab provides a wide range of tools to transform your
data and derive additional insights. This tab enables you to extend the capabilities of
your data model and tailor it to your specific analysis requirements.
The View tab in Power Query provides options to customize the visual appearance and
layout of the Power Query Editor window. It allows you to change the zoom level,
toggle the Formula Bar display, show or hide gridlines, and adjust the column widths.
The View tab also offers options to enable or disable the Formula Bar autocomplete
feature and configure the display of formula errors. These customization options help
improve the overall user experience and make working with Power Query more
efficient.