Power Query

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

KNACK TRAINING

A BEGINNER’S
GUIDE TO
POWER QUERY
POWER QUERY FOUNDATIONS

WHAT IS POWER QUERY?


Many people’s whole job can be boiled down to three steps - Extract data from places like
spreadsheets, comma-separated values, databases, and more; Transform that data so that it is clean,
accurate, and properly formatted, and Load the data into a report. Power Query is the ETL tool in
the Microsoft BI suite - whether you’re talking about Excel or Power BI, when you extract, transform,
and load the data into a report, you’re doing it with Power Query.

If you think about the techniques that are usually involved in this ETL process, you see things like
copying-and-pasting content into spreadsheets, using functions like VLOOKUP, and automating
steps with macros. All of these have issues and concerns, and Power Query improves upon all of
them. Some of the most powerful and useful replacements for these functions are in this PDF.

!
GETTING POWER QUERY
If you have Excel 2010 or 2013, you’ll need to install the Power Query Add-in -
https://knack.link/MSFT-PQ-2013DL. Once it’s installed and enabled, you’ll have a Power
Query Tab.

If you have Excel 2016, 2019, or Office 365, look at the Data Tab for Get Data - that’s Power
Query!

If you want to try out Power BI Desktop, click Get Data, and you’ll be in Power Query, as well.

Well, enough talking about it - let’s get into the meat of this incredible tool.

KNACK TRAINING 2
POWER QUERY FOUNDATIONS

CONTENTS
What is Power Query? 2
Extracting Data 4
Transformation 1: Text to Rows? 7
Transformation 2: European Divisions 10
Transformation 3: Date Math 12
Loading 13

BEGINNER’S GUIDE TO POWER QUERY 3


POWER QUERY FOUNDATIONS

EXTRACTING DATA
Begin by launching the Power Query Editor in Excel - either through the POWER QUERY tab in
Excel 2010 or 2013, or by clicking Get Data > Launch Power Query Editor from the Data tab. (see
below for the Excel 2013 and Office 365 buttons)

Now you have the Power Query Editor open, and you can see the New Source drop-down. From
here, you can extract data from any source you like. You’ll see that there are options, depending on
what source you choose. For example, if you select an Excel file, you can get the data from a sheet,
a named range, or a table. (We recommend using tables in Excel, if you haven’t already gotten into
them. See more about tables on our YouTube channel: https://knack.link/YT-ExcelTables)

KNACK TRAINING 4
POWER QUERY FOUNDATIONS

You can even extract data from a website - especially if that website has a table that Power Query
can reference. As an example, you can connect to x-rates.com to get the most current exchange
rates between countries:

The result is a table of data, still in Power Query, ready to be tweaked - transformed - before it’s
ultimately loaded into Excel (or Power Query).

BEGINNER’S GUIDE TO POWER QUERY 5


POWER QUERY FOUNDATIONS

THE SETUP
As you can see, there are four major areas of the screen:

In the center is the table you’re currently working on. On the left is a list of all the tables you’re
working on in this spreadsheet - your queries. It’s a good idea to double-click any of those names to
rename a query and make it more easily understood.

At the top of the screen are the Ribbons of tools for transformations. In here, you’ll see that you can
create new columns, split columns, change data types, etc.

Then, on the right is the list of all the steps you’ve taken - all the transformations you’ve done.
Notice that you can change a step by clicking the gear icon, or remove a step by clicking the X
button.

Let’s take a look at some really amazing transformations that Power Query makes easy.

KNACK TRAINING 6
POWER QUERY FOUNDATIONS

TRANSFORMATION 1: TEXT TO ROWS?


Scenario: You have a list of dates, and multiple stores have sales going on
each date. Unfortunately, someone typed every store into the same cell!

Notice the problem here? If you want a report of every sale Store #1032 ran, that store is mixed in
with all the others. Each store needs a separate record for each date. How are you going to make
that happen?

If you were in Excel, you’d probably either hand-type everything (ugh), or you’d use Text to Columns
to break up each of the entries (using the semicolons). The problem with that is you could have a
dozen or more columns, and then you’d still need each of the entries to be its own row.

Because you’re in Power Query, you can split this column up, but split into individual rows
automatically (to follow along, download the files from https://knack.link/PQB-Files):

BEGINNER’S GUIDE TO POWER QUERY 7


POWER QUERY FOUNDATIONS

So, we’ve got the file open in Power Query. Click the column in question, and choose Transform >
Split Column > By Delimiter:

KNACK TRAINING 8
POWER QUERY FOUNDATIONS

Now, under Advanced Options, choose Rows:

Did you see how easy that was?

BEGINNER’S GUIDE TO POWER QUERY 9


POWER QUERY FOUNDATIONS

TRANSFORMATION 2: EUROPEAN DIVISIONS


You work for a large, multinational conglomerate, and multiple times a
week, your European divisions send you CSV reports that have lots and
lots of dates. And every one of those dates gets misread by Excel. Every
time. It’s exhausting - or it was.

So here’s our issue. When we double-click the CSV to open it in Excel, the spreadsheet mistranslates
26-07-2009 as just a random set of characters. You need some complicated date functions to re-
translate the dates - or you need Power Query. Extract the Dates.csv file from the exercise files, and
let’s get to work.

You can tell by the little ABC graphic in the corner of IN SVC DATE that Power Query currently thinks
this column is text - just like Excel would. However, click the ABC button, and this happens:

KNACK TRAINING 10
POWER QUERY FOUNDATIONS

The last one - Using Locale... - is the one you want. You need to tell Power Query that your dates
are coming from a different locale.

Again - do you see how easy that was? Let’s do one more.

BEGINNER’S GUIDE TO POWER QUERY 11


POWER QUERY FOUNDATIONS

TRANSFORMATION 3: DATE MATH


All our depreciated assets tell us the exact day they came into service -
but we want to know the quarter they came into service. What a pain,
right? Wrong.
While you’re working on Dates.csv, let’s create a new column based on the IN SVC DATE. Click Add
Column > Date > Quarter > Quarter of Year or End of Quarter (or both, experiment!).

Seriously - that’s just too easy.

KNACK TRAINING 12
POWER QUERY FOUNDATIONS

LOADING
You’ve done all the transformations you need, so now it’s time to let Excel
or Power BI do their job - calculations and visualizations.
At the end of the process, find the Close & Load button on the Home tab - you’ll see two options on
the drop-down:

Close & Load will put all the data into a sheet in Excel, allowing you to work on it there. That’s the
typical workflow.

Close & Load To..., on the other hand, lets you add your data as a connection, if you’re building
something more complex that requires multiple data connections.

After clicking Close & Load, we now have a Query tab, complete with a button to Refresh the query
and get the latest version of the data.

BEGINNER’S GUIDE TO POWER QUERY 13


POWER QUERY FOUNDATIONS

THANK YOU!
If you’ve read this far, I think you’re sold on Power Query. It’s inclusion in both Excel and Power BI
make your skills easily transferable - all the more reason.

If you’re interested in learning more Power Query from Knack Training, email us at:
info@knacktraining.com

KNACK TRAINING 14

You might also like