0% found this document useful (0 votes)
78 views

Excel Power Query For Beginners

Uploaded by

andersonsantiago
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Excel Power Query For Beginners

Uploaded by

andersonsantiago
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Saskia Gießen

Excel: Power Query for


Beginners
A Step by Step Guide
SASKIA GIESSEN

EXCEL: POWER QUERY


FOR BEGINNERS
A STEP BY STEP GUIDE

2
Excel: Power Query for Beginners: A Step by Step Guide
1st edition
© 2022 Saskia Giessen & bookboon.com
ISBN 978-87-403-4261-1
Name and title of reviewer: Hiroshi Nakanishi

3
EXCEL: POWER QUERY FOR BEGINNERS Contents

CONTENTS
Preface 6

1 Introducing Power Query 7


1.1 Where can I get Power Query? 7
1.2 What does Power Query do? 7

2 Creating your first query 10


2.1 Importing Data to Power Query 10
2.2 Editing the Data 13
2.3 Variations of the data transfer 21

3 Important Information about working with queries 26


3.1 The command bar at the bottom of the Peek window 27
3.2 Deleting the worksheet containing the table 27
3.3 Basic information about Connections 28
3.4 Dynamic Tables 30

4 Editing cell content 33


4.1 Bringing Excel data to Power Query 33
4.2 Splitting text 35
4.3 Replacing values 37
4.4 Splitting content 39
4.5 Deleting columns 40
4.6 Sorting 41
4.7 Copying and modifying a query 42

5 Import Several Files in one Step 45


5.1 The data that will be imported 45
5.2 Choosing the files to import 45
5.3 Bring all tables together 47

6 Extracting data from an Excel spreadsheet 51


6.1 The complex spreadsheet 51
6.2 Extracting part of the Data 51
6.3 Cleaning up the data 53
6.4 Create calculations in new columns 53
6.5 Transferring the Data to Excel 56
6.6 Analyzing the Data with PivotTables 57

4
EXCEL: POWER QUERY FOR BEGINNERS Contents

7 Merging multiple Spreadsheets 60


7.1 The Workbook and its four worksheets 60
7.2 Appending several queries to each other 64
7.3 Working with the consolidated table 69
7.4 Inserting another Table 69
7.5 Storing queries in folders 72

Index 73

5
EXCEL: POWER QUERY FOR BEGINNERS Preface

PREFACE
This manual was written to accompany our seminar on Microsoft Power Query. Its target
audience is users who need to import external data into Excel or transform data into Excel
before further processing.

The exercises in the book are easy to understand and can be adapted with little effort to
your own needs.

Power Query has very comprehensive feature set which is also easy to use. The software can
do a great deal of work for you without requiring any programming skills.

The output of Power Query is a list that you can then use for further analysis in Excel or
in the data model of PowerPivot.

You can download the sample files from the following website:

https://bit.ly/3xxFXR1

Please also read my book Power Query for Advanced

Saskia Gießen

Cologne, Germany

April 2022

6
EXCEL: POWER QUERY FOR BEGINNERS Introducing Power Query

1 INTRODUCING POWER QUERY


This chapter provides setup tips and an overview of the power of Power Query.

1.1 WHERE CAN I GET POWER QUERY?


Starting with Excel, Power Query is included in the Data tab in the first group, Get &
Transform Data.

Figure 1-1: The commands relating to Power Query in Excel

Power Query is an Excel add-in that runs in its own task. The content you create in Power
Query are called Queries and stored in the current Excel workbook.

1.2 WHAT DOES POWER QUERY DO?


Power Query can import data from a great variety of sources. It also has functions to
transform the data before bringing it into Excel.

The add-in is a master of ETL, a widely used acronym for Extract, Transform and Load.

1.2.1 WHAT KINDS OF DATA CAN POWER QUERY IMPORT?

Power Query can access a wide variety of data sources. The following table provides an
overview and shows the file types in the group Get & Transform Data.

7
EXCEL: POWER QUERY FOR BEGINNERS Introducing Power Query

Online
Web File Database Azure Other
Services

Web Excel SQL-Server Azure SQL Sharepoint Table/Range


(URL) Workbook Online (Excel)

Text/CSV Microsoft Azure Microsoft Web


Access SQL Data Exchange
Warehouse Online

XML Analysis- Azure Dynamics Microsoft Query


Services HDInsight 365
(HDFS)

JSON SQL Server Azure BLOB Facebook SharePoint List


Analysis
Services

Folder Oracle Azure tabular Salesforce Odata Datafeed


storage Objects

SharePoint- IBM DB2 Azure Data Salesforce Hadoop File


Folder Lake Store Reports

MySQL Active Directory

PostgreSQL Microsoft
Exchange

Sybase ODBC

Teradata OLEDB

SAP HANA Empty Query

Table 1.1: Power Query can work with these diverse data sources

1.2.2 THE POWER QUERY TOOLS

The toolbox is brimming with a variety of tools. Here are some of the available transformations:

Keep and delete rows or columns


Use the first row as column headers
Sort and filter
Set data type
Search and replace

8
EXCEL: POWER QUERY FOR BEGINNERS Introducing Power Query

Extend columns to get detail information from associated data structures


Format column content
Split or merge columns
Delete duplicate rows
Append results of several queries in one result
Merge queries (similar to VLOOKUP in Excel)
Group by column with various aggregation methods, including count, sum or
column cardinality
Pivot data
Unpivot cross tables and hierarchical lists
Insert index columns
Insert user defined columns
Many integrated functions for modifying column content
Flexible parameterized queries
Manual query editing with the Advanced Editor
User defined functions

In the following chapters all these actions and commands will be explained and illustrated
with practical examples. The commands can be used in combination, and this makes Power
Query truly a master of data transformation.

9
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

2 CREATING YOUR FIRST QUERY


Power Query is a tool for creating queries. The query stores the data access information and
the definitions of the transformations. As a result, you can use a query defined once to access
data with a similar structure over and over on separate datasets without additional effort.

This chapter provides information about how to import external data using Power Query.
The import is described in an example using the text file shown below.

Figure 2-1: The goal is to import this CSV file

During the import process, you work in a window separate from Excel called the Query Editor.

The Editor window provides additional information about Power Query. There are several
ways to transfer your data to Excel after the external data has been prepared and transformed.

2.1 IMPORTING DATA TO POWER QUERY


In this step, you import the data into the Query Editor of Power Query.

Start Excel with a new empty folder.


Activate the Data tab and click the From Text / CSV button.

Figure 2-2: Accessing external data from a CSV file

10
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

In the Import Data window, choose the file containing your data and click Open.

A window opens with the file name as its title. You can now make several settings that you
later no longer need to repeat in Power Query.

Figure 2-3: The first settings before importing begins

In most cases, Power Query recognizes the File Origin and the Delimiter. For this example,
the data type detection is not used because the first four lines of the file either contain text
or are empty.

Click the Edit button.

By clicking on the Load button, you would have imported the file as it is to Excel.

The query editor provides a preview of the data.

11
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

Figure 2-4: The CSV file in the Query Editor

2.1.1 THE QUERY EDITOR SCREEN

You can edit the retrieved data using the tabs Home, Transform, Add Column and View.

The Navigator Pane on the left shows all the queries in the Excel workbook. You can
expand or collapse it with one click.

In Query Settings on the right, you can enter a descriptive name in the Name field of your
query. In the APPLIED STEPS section, you will see a list of the commands that you or
Power Query has performed.

The status bar tells you how many columns and rows have been retrieved.

Directly above the status bar you can see the content of the selected cell. If you select an
entire column, this area disappears.

12
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

Figure 2-5: A guide to the different parts of the Query Editor

Info: The command View / Formula bar shows or hides the formula bar. The formula bar
displays the command selected in the query settings area.

2.2 EDITING THE DATA


Now you can edit the data you have retrieved. All the commands you need for the next
steps can be found on the Home tab. To be complete, we would like to point out that
you can also find many commands in the context menu of the right mouse button and the
button which is just above line one and to the left of the first column.

Note that Power Query does not change the data in the original file! All the editing
steps you do in Power Query are done on a copy of your data.

2.2.1 REMOVING THE TOP ROWS

In this step we will delete the top four rows.

Choose Home / Reduce Rows / Remove Rows / Remove Top Rows.


In the Number of rows box, enter 4 for this example.

13
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

Figure 2-6: The number of rows to be removed

Confirm with OK.

The first four lines have now been removed. In the preview, the remaining lines slide upwards.
In the edit bar and in the APPLIED STEPS area on the right you see your command
Removed Top Rows.

Figure 2-7: Your process steps are logged

By clicking on the icon to the left of the Removed Top Rows command, you can undo
this command. Click on the gear in the APPLIED STEPS pane to change the number of
lines the command removes.

14
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

2.2.2 USING THE FIRST ROW AS A HEADER

In the second step, you can use a command to move the contents of the first line into the
column titles. By default, Power Query labels columns with Column1, Column2, and so on.

Choose Home / Use First Row as Headers.

Figure 2-8: Using the first row of the table as column headers.

Now the first row of the table has moved into the column headers.

The next step is changing the types of data in the columns.

Discover our eBooks on


Time Management Skills
and hundreds more

Download now

15
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

Change the data types of the columns


Now you have to check and possibly adjust the data types.

Figure 2-9: The data types are displayed in the column headers

Excel can only calculate if the data type is correct, so you should choose the correct data
type for each column in this step.

In the Date column, click the icon and select the data type DATE.

Figure 2-10: Choosing the data type

Confirm the question about changing the data type with Replace current.
Select the column Gross_profit and choose the data type Currency.

Info: Power Query does not assign a currency symbol to the values, even if you select the
Currency data type. You will need to do this later in Excel.

Here you can see from the icon in the column title which data type you have selected.

16
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

The pane APPLIED STEPS on the right summarizes your last three actions in a Changed
Type1 command.

Figure 2-11: The correct data types have now been assigned to the columns

2.2.3 REMOVE SELECTED COLUMNS

In the final step we remove unneeded columns from the data import.

Click in the No_Material column and use the Home / Manage Columns / Remove
Columns command.

Select the Cat_No column, hold down the >6KLIW@ key, and click the Cust_City
column. Press the >'HO@ key.
Remove any empty columns.

Figure 2-12: Removing some of the columns from the import process

As before, Power Query saves these steps in the APPLIED STEPS section. In this case it
is the Removed Columns command.

This is all the processing we need. Your table is now ready to be transferred to Excel.

17
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

2.2.4 THE APPLIED STEPS AREA

All the commands you have run are displayed in the APPLIED STEPS area on the right.
You can show or hide this area using the View / Query Settings command.

When you click on a command, the Power Query displays the state of the data after that
command is executed.

Figure 2-13: The state of the data after the Promoted Headers command

If you select the last step, you see the final state of your work. When the data is transferred
to Excel, it is always transferred in this final state, regardless of which command is currently
selected.

Important! If a processing step is selected other than the last one in the list and you insert
a command, for example Removed Columns, the following message box appears:

Figure 2-14: Power Query warns you before inserting an intermediate step

Power Query asks if you want to insert this step at the highlighted position.

Commands with a gear to the right can be edited by clicking on the icon. For example,
this allows you to change the path or filename for the Source command.

18
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

For the Removed Top Rows command, click on the gear to change the number of lines
to be removed.

Info: You can change the order of steps using the context menu with the commands Move
Up or Move Down. The context menu also contains a Properties dialog. This allows you
to document each step separately.

This completes all your work in Power Query.

2.2.5 WHAT DID POWER QUERY STORE?

Before you import the data to Excel, take a quick look at the commands that Power Query
recorded for you. The steps are detailed in the programming language M.

To view the script, select Home / Advanced Editor.

Figure 2-15: The code for the steps you created

The Advanced Editor allows you to make changes to your script as well as just viewing it.
For example, you might want to keep one of the columns deleted in the script. If you click
the button in front of the Removed Columns command, all columns will be displayed
again. But you can restore a single column in the editor. This is done by deleting just the
column name and its accompanying syntax, which is the quotation marks and the comma
separating the column names.

Click Done to apply your changes.

19
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

2.2.6 TRANSFERRING THE DATA TO EXCEL

When you have finished editing, you can transfer the data to Excel. This creates a workbook
query in Excel, which is stored in the Excel workbook.

In the Home tab, click on the upper part of the Close & Load button.

Figure 2-16: The command to transfer your data

This closes the Query Editor and inserts the data as a dynamic table on a new worksheet.

Info: To get back to the Query Editor, select Query / Edit or Data / Get & Transform
Data / Get Data / Launch Power Query Editor.

Figure 2-17: The imported data and the tabs Design and Query in Excel

Info: Later in this chapter we’ll dive deeper into how to handle a query in Excel and how
to use a dynamic table.

This step increases the physical size of the spreadsheet file. The imported data is now
contained in the workbook.

20
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

2.3 VARIATIONS OF THE DATA TRANSFER


When you click the Close & Load button, you transfer the data to a new Excel spreadsheet.
If you click on the lower part of this button, you also have the option Close & Load To.
This opens a window that offers you several transfer options.

Now if you go back to Power Query with the Query / Edit command and click on the
lower part of the Close & Load button, the Close & Load To command is inactive.

Power Query itself does not allow you to change from your original choice. But not to
worry, in Excel there is still a way to change this option.

Figure 2-18: Loading data to Excel

There are four variations on the way you transfer data. The following sections provide an
overview of all four variations.

The following four options are available:

Output the data to Excel on a new spreadsheet


Choose a worksheet and insert the data on it
Transfer the data to Excel and add it to an existing PowerPivot data model
Link the data to Excel

2.3.1 VARIATION 1: OUTPUT THE DATA TO EXCEL ON A NEW SPREADSHEET

The first variation transfers the whole table to a new worksheet. This is the step you have
already done above.

Select Home / Close & Load.

This closes the Query Editor and inserts the data as a dynamic table on a new worksheet.

21
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

2.3.2 VARIATION 2: CHOOSE A WORKSHEET AND INSERT THE DATA THERE

To insert the table in an existing worksheet of your choice, perform the following steps:

In the Power Query Editor, choose Home / Close & Load To.
Choose the option Existing worksheet.

Power Query provides a cell reference as the starting point for the data insertion. You can
edit the cell reference.

Click on the sheet and in the cell where you want the data inserted.

Figure 2-19: Inserting the table in a specific place

Click the OK button.

As in the first case, the table is inserted as a dynamic table. The only difference to the first
variation is that you can determine the place where the table is inserted.

2.3.3 VARIATION 3: SEND THE TABLE TO EXCEL AND TO THE


POWERPIVOT DATA MODEL AT THE SAME TIME

If you want to analyze a table in PowerPivot, you can push it directly to the PowerPivot
data model.

Choose the command Home / Close & Load To.


Check to box Add this data to the Data Model.

22
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

Figure 2-20: Pushing data to the spreadsheet and into the Data Model at the
same time

As explained above, the table is transferred as a dynamic table to Excel. At the same time,
it is inserted into the data model.

To check this, select Data / Data Tools / Go to the Power Pivot Window. If you
are starting PowerPivot for the first time, click OK.

Figure 2-21: The table in the PowerPivot data model

23
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

If you pass the table to both Excel and the data model, the file size is greatly expanded.
There are two sets of data in the workbook. If you only need the data in PowerPivot, select
Only Create Connection, which is described in the next section.

2.3.4 VARIATION 4: ONLY CREATE CONNECTION

The last variation creates a connection to the data. The data is not shown in Excel on a
worksheet and the file size does not change.

Choose Home / Close & Load To.


Select the option Only Create Connection.

Figure 2-22: Only Create Connection

After you click OK, you see the following.

Figure 2-23: Only a data connection

24
EXCEL: POWER QUERY FOR BEGINNERS Creating your first query

There is only a data connection to the information in Power Query. The data can still be
used later in various ways.

A connection takes very little storage space.

Changing your selection


Suppose you selected the Only Create Connection command. Now you want to change
this and still see the table in the Excel worksheet.

In the Query & Connections section, right-click the query that you want.
Select the Load To command.

The Import Data window opens, and you can change your selection.

Info: The command Data / Query & Connections show the task area if it is hidden.

Discover our eBooks on


Communication Skills
and hundreds more

Download now

25
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

3 IMPORTANT INFORMATION
ABOUT WORKING WITH QUERIES
Each query is stored in the worksheet where it is visible. But the Connection queries works
a little differently. They are stored directly in the workbook. This section assumes that you
have imported the table into a worksheet.

On the right edge of the screen, you should be able to see all the workbook queries in the
current Excel workbook. Click on a query to display the worksheet with the corresponding
table.

If you do not see this area, choose Data / Query & Connections.

Info:
Open the Power Query Editor by double clicking the query.

When you point to the query name, the information for the current query is displayed
out. This section is called Peek. You get a preview of the data and more information about
the query.

Figure 3-1: The Peek shows you all the information about the query

26
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

3.1 THE COMMAND BAR AT THE BOTTOM OF THE PEEK WINDOW


There are four options at the bottom of the Peek.

VIEW IN WORKSHEET activates the worksheet with the table of the query. Clicking
EDIT opens the query editor.

If you click on the three dots, you get a selection of additional commands.

Figure 3-2: Additional commands in the Peek window

When you click DELETE the following warning is displayed:

Figure 3-3: Deleting a query

When you click Delete, the query is deleted, but the table remains. The Query register
disappears, and 0 Query is displayed in the Query & Connections pane.

Info: You can’t undo this step.

The commands in the Peek are also available in the context menu when you right click the
query in the Query & Connections area.

3.2 DELETING THE WORKSHEET CONTAINING THE TABLE


You might need to delete the worksheet with the dynamic table, but still want to keep the
query.

27
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

After you call the command to delete the worksheet via Home / Delete / Delete Sheet
and confirm the first security prompt with a click on Delete, Excel sets up a connection
to the data for you. That means the query is still there.

Figure 3-4: A connection to the Query was created automatically

By right-clicking on the query and using the Load To command, you can use the Table
and New Worksheet options to re-insert your data as a dynamic table.

3.3 BASIC INFORMATION ABOUT CONNECTIONS


If you’ve created a connection and you want to do something like creating a PivotTable,
you’ll need to do the following:

Select the command Insert / PivotTable.


Chose the option Use an external data source.

Figure 3-5: Creating a PivotTable from a Connection

Click the Choose Connection button.


Highlight your connection and click Open.
Click Open and create your pivot table.

28
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

3.3.1 MANAGING QUERIES

Once you have started working with the product, and you have multiple queries in a
workbook, Excel offers the option of presenting them in a structured manner.

Right-click the query for the context menu, and then create a folder using the Move to
group / New group command. Now you can move queries to this folder. Note that this is
only possible via the context menu. Once you have created a folder, all remaining queries
will be moved to the Other Queries folder.

Figure 3-6: Managing Queries

You can change the order of the queries in the group with the Move Up and Move Down
commands.

3.3.2 OPENING A FILE

When you open an Excel workbook that contains a query, you are warned that there are
external connections in the workbook.

Figure 3-7: The warning about external connections

Click the button Enable Content.

You may also see a warning that your Excel spreadsheet is receiving data from a network.
Enable the content.

If you ignore the security warnings and you try to refresh or edit the query, the following
message appears:

29
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

Figure 3-8: Activating the connection

Now you need to click the Yes button to work with the query.

3.4 DYNAMIC TABLES


The output of a Power Query query is a dynamic table. This section gives you a brief
overview of the functions dynamic tables provide.

If you have transferred the table to Excel, the two tabs Query and Design are available in
the worksheet tabs at the top of Excel.

Click in the table to activate the Design tab.

Figure 3-9: The Design tab for dynamic tables

When the cursor is in the table and you scroll down, the first line does not scroll with the
rest of the table. The column headers are displayed as column titles.

Figure 3-10: The first row is automatically fixed

You can change the colors in the Table Styles command group on the Design tab.

You can make further adjustments in the Table Styles Options command group to the left,
such as Header Row, Banded Rows, First Column, Last Column or Banded Columns.

The filter is activated by default for the dynamic table. Use the Filter Button checkbox to
disable it.

30
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

The data slicer provides user friendly filter functions.

Use the Insert Slicer button to insert visual filter buttons.


Select the fields you want to filter.

Figure 3-11: Selecting a slicer field

Hold down [Ctrl] and select one or more entries to filter for. You can also use the
Multi-Select button to enable multiple entries.

Figure 3-12: Filtering with slicers

Remove the filter with a click on the button in the slicer.

Dynamic tables allow users to create calculations in just a few clicks.

Check the Total Row check box in the Table Style Options area.

Figure 3-13: Activating the total row

Scroll down to the last row of the table.

31
IMPORTANT INFORMATION ABOUT
EXCEL: POWER QUERY FOR BEGINNERS WORKING WITH QUERIES

Figure 3-14: The last column of the table is automatically calculated

The last column of the table is aggregated in the total row. If the column is numerical, the
default calculation is a sum. Otherwise it is a count.

Click another cell of the new result row.


Select a calculation method from the dropdown list.

Figure 3-15: Creating a new calculation in the total row.

When the table is refreshed and new rows of data are added, the result line automatically
moves down and the calculations are updated.

When you create a dynamic table, it automatically gets a range name. The name is visible
and can be modified in the Table Name field on the Design tab.

32
EXCEL: POWER QUERY FOR BEGINNERS Error! Use the Home tab Editing
to applycell
Überschrift
content 1 to
the text that you want to appear here.

Editing
4 cell content
EDITING CELL CONTENT
In mostcases,
In most cases,imported
imported data
data has has
to betoedited
be edited (or »transformed«)
(or »transformed«) before itbefore
can beitanalyzed.
can be analyzed.
The tools in
The tools in Power Query let you split, merge, replace, and
Power Query let you split, merge, replace, and cleanse cell content.
cleanse cell content.

 Open
Openthethe Chapter4_1.csv.
filefile Chapter4_1.csv.

This chapter
chapterwill
willintroduce
introduceyou
you
to to a set
a set of of commands
commands thatthat allow
allow you
you to toyour
edit edit data
yourefficiently.
data efficiently.

Figure 4-1:
Figure 0-1:There
Thereareare several
several problems
problems withtable
with this this table

The No_Material column contains the material number and name together in a single cell. Some of the
The
namesNo_Material column contains
of the sales representatives in thethe materialcolumn
Rep_Name number anddigits
have name together
in them. The in a single
column cell.
Cust_City
Some ofthe
contains thecustomer
names ofname
the and
saleslocation
representatives
separated in
bythe Rep_Name column have digits in them.
a hyphen.
The column Cust_City contains the customer name and location separated by a hyphen.
Power Query helps you deal with these problems without having to enter a single formula. But before we
Power Query
get started, we’llhelps
have you deal
a look withtothese
at how move problems without
data from an having
open Excel to entertoa Power
spreadsheet singleQuery.
formula.
But before we get started, we’ll have a look at how to move data from an open Excel
spreadsheet to Power Query.
Bringing Excel data to Power Query
The steps to get data from Excel into Power Query are converting the table to a dynamic table, renaming
it, and then passing it to Power Query.
4.1 BRINGING EXCEL DATA TO POWER QUERY
Click anywhere in the table and press [Ctrl] + [T].
The steps to get data from Excel into Power Query are converting the table to a dynamic
Make sure that Excel automatically included all the cells in your table in the Create Table window.
table, renaming it, and then passing it to Power Query.

Click anywhere in the table and press >&WUO@ + >7@.


Make sure that Excel automatically included all the cells in your table in the Create
Table window.

39

33
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Figure 4-2: Checking which cells will be included in the dynamic table

Confirm with OK.

In the last chapter we saw how to handle a dynamic table. The only editing step you need
is naming the table. Power Query uses this name as the query name.

Leave the cursor in the table and click on the Design tab.
Enter the new name, List1, in the Table Name field and press [].

Figure 4-3: The dynamic table with a new name

Now the table is just one click away from Power Query.

Select Data / Get & Transform Data / From Table/Range.

34
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Figure 4-4: The command to transfer data to Power Query

This command transfers the data in the table to the query editor. The name of the table is
used as the query name by default.

Figure 4-5: The table Power Query

You can still change the query name.

4.2 SPLITTING TEXT


The content of the No_Material column needs to be split into two columns. The first five
characters belong in a separate column. The command is pretty simple. However, you want
to keep the No_Material column so you can check your work. So, we’ll create a copy of
the column before we split it.

35
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Figure 4-6: The material number and name don’t have any separator

Right-click the column title No_Material and select the command Duplicate
Columns.

The new column appears beside the table to the right of the last column.

Drag the new column titled No_Material-Copy and drop it to the right of the
column No_Material.
Leave the No_Material-Copy column highlighted and select Split Column / By
Number of Characters on the Home tab.
Enter 5 in the field Number of characters to split out the five digits of the material
number. It’s important to activate option Once, as far left as possible. You need this
option because you know that column has to be split after the first five characters.

Figure 4-7: Making two columns out of one

Confirm with OK.

36
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

The column splits into two columns. The contents are separated at the position specified.
The titles of the new columns are No_Material - Copy.1 and No_Material - Copy.2. Power
Query has also converted the data type of the first column to Whole Number.

Right click each column and use the Rename command to change their names to
Material_No and Material.

Figure 4-8: The result: Two columns with separated data

You now have two new columns containing the numbers and names separately. In addition,
you kept the original column by copying.

4.3 REPLACING VALUES


In the next step we’ll remove the digits 1 und 2 from the Rep_Name column.

Figure 4-9: Getting rid of unneeded characters

Select the column Rep_Name. Choose Home / Replace Values. The command is
also available in the context menu with the right mouse button.
Enter 1 in the Value To Find field.
Leave the Replace With box empty.

37
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Figure 4-10: Replace each 1 with an empty string

Confirm with OK.

The unneeded character 1 in all rows are removed.

Repeat the same steps with 2.

Figure 4-11: The unneeded characters have disappeared

The values in the column Rep_Name have now been cleaned up.

38
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

4.4 SPLITTING CONTENT


In the next example, the customer names and their cities ended up in the same column
and need to be separated.

Figure 4-12: The goal is to separate on the dash

Select the column Cust_City.


Choose the command Home / Split Column / By Delimiter.
Choose --Custom-- from the dropdown list in the Select or enter delimiter field.
In the field below, enter a space followed by a hyphen [-] and another space.
Activate the option Rightmost delimiter.

Figure 4-13: A user defined separator

Confirm with OK.

Now the values in the columns Cust_City are split into two columns.

Rename the new columns to Cust_Name and Cust_City.

39
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Figure 4-14: The result: The data is in two columns

4.5 DELETING COLUMNS


Since you don’t need all the columns you have in the next steps, delete the ones you do
not require.

Delete the columns No_Material, Material_No, Cat_No, Base_price, Retail_price


and Rep_No.

Figure 4-15: The data is now ready.

40
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

4.6 SORTING
In the last step, you want to sort your data. First, sort by sales representative name. For
each sales representative, the data should be sorted again by the material.

Click the column Rep_Name and choose Home / Sort Ascending . You can
also use the filter symbol.
For the Material column, click the filter symbol und choose the command
Sort Ascending.

Figure 4-16: Two different ways to sort

The content of the Rep_Name column is now sorted alphabetically. The Material column
is also sorted by material name for each sales representative.

4.6.1 PUTTING THE DATA BACK INTO EXCEL

We finish processing by returning the data to Excel.

Choose the command Home / Close & Load.

Figure 4-17: The transformed data is back in Excel

Save the worksheet and leave it open.

41
Error! Use the Home tab to apply Überschrift 1 to
the text that you want to appear here.
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Editing cell content


4.7 COPYING AND MODIFYING A QUERY
Imagine the situation
In most cases, where
imported data hasyou have
to be another
edited Excel spreadsheet
(or »transformed«) before in another
it can workbook
be analyzed. that in
The tools
you also want to clean up. The structure is identical to that of the first table.
Power Query let you split, merge, replace, and cleanse cell content.

 Open
Openthethe Chapter4_1.csv.
filefile Chapter4_2.csv.

Make
This chapter willthe table you
introduce a dynamic table
to a set of and name
commands it List2.
that allow you to edit your data efficiently.

Figure 0-1: There are several problems with this table

The No_Material column contains the material number and name together in a single cell. Some of the
names of the sales representatives in the Rep_Name column have digits in them. The column Cust_City
contains the customer name and location separated by a hyphen.

Figure 4-18: Another table that need to be edited


Power Query helps you deal with these problems without having to enter a single formula. But before we
get started,
You we’ll have areuse
can completely look at
thehow to move
query justdata from here.
created an open Excel spreadsheet to Power Query.

Bringing
Power Excel
Query data
queries canto
bePower Query
copied and pasted into other workbooks.
The steps to get data from Excel into Power Query are converting the table to a dynamic table, renaming
Switch
it, and then toitthe
passing workbook
to Power Query.with the query and double-click the query or select Query
/ Edit.
Select the query in the left pane and copy it.
Click anywhere in the table and press [Ctrl] + [T].
Close Power Query and switch to the new workbook.
Make sure that Excel automatically included all the cells in your table in the Create Table window.
Select the command line Data / Get & Transform Data / Launch Power Query
Editor. This starts Power Query without a query.
Right-click in the left query area and select the Paste command.

39

Figure 4-19: Inserting a query

42
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

The query is inserted and immediately shows an error message.

Figure 4-20: The error message

Choose the command Home / Advanced Editor.

In the first line of the query, Power Query accesses the dynamic table List1. Your dynamic
table is called List2.

Modify the code in the first line of List1 to List2. Be careful not to delete the
quotes.

Figure 4-21: Just a small change

Click Done.
Change the name of the query.

Now the query will run again, and you will see the imported table.

43
EXCEL: POWER QUERY FOR BEGINNERS Editing cell content

Figure 4-22: This query was extended by one step

Now you can transfer the data to Excel with the Close & Load command on the Home
tab and continue editing there.

This shows how queries can be copied and used to modify other data.

44
EXCEL: POWER QUERY FOR BEGINNERS Import Several Files in one Step

5 IMPORT SEVERAL FILES


IN ONE STEP
In this chapter, you will learn how to import multiple files stored in the same folder in one
step. Power Query turns out to be extremely well suited to this task.

5.1 THE DATA THAT WILL BE IMPORTED


In this example, there are four Excel files and two PNG files in one folder. The number of
files does not matter here. The two PNG files are not imported. They play a passive role
in the example.

This is what the folder contains. Not all the files will be used for importing.

Figure 5-1: Only the Excel files are to be imported

The column structure of the four Excel files is different as is the number of rows of data.
What is important is that the name of the worksheets is identical.

5.2 CHOOSING THE FILES TO IMPORT


It’s easy to combine several files in Power Query.

Create an empty workbook and use the command Data / Get & Transform Data /
From File / From Folder.

45
EXCEL: POWER QUERY FOR BEGINNERS Import Several Files in one Step

Figure 5-2: Selecting the command

In the Folder window, click on the Browse button and select the folder where the
files you want to import are located.

Figure 5-3: The path to the folder

Confirm with OK.

Power Query returns a list of the files in the selected folder. First get all files for Power
Query and then exclude the unnecessary files.

46
EXCEL: POWER QUERY FOR BEGINNERS Import Several Files in one Step

Figure 5-4: These are the files Power Query found in the selected folder

Click the Edit button.

5.3 BRING ALL TABLES TOGETHER


The file metadata is now transferred to Power Query. Each file has a separate row.

Figure 5-5: These files are in the current folder

Use the filter to remove the files you don’t want.

Open the filter on the Extension column.


Use the filter to deactivate all the files you do not want to import.

47
EXCEL: POWER QUERY FOR BEGINNERS Import Several Files in one Step

Figure 5-6: The files unneeded types are deactivated

Confirm with OK.

Now there are only Excel files in the list. Power Query protocols your choices in the Query
Settings area on the right.

Figure 57: These four files will be imported

Before clicking on the button in the Content column, consider which columns you
want to move and in what order you want to move them. The first file in the list specifies
the order of the columns. If one of the other files has an additional, it will appear after the
column of the first file.

Click the button with the two arrows in the first column, Content .
Select the table where the data you want to import is located. In this example, it
is the Data table.

48
EXCEL: POWER QUERY FOR BEGINNERS Import Several Files in one Step

Figure 5-8: Selecting the table

Confirm with OK.

In the left pane, you can see that Power Query has done a lot of work for you, putting
these four files together.

Figure 5-9: The content of the four files in the Query Editor

The first column contains the file name of the source of the data in each row. You don’t
need this information, so you can delete the column.

49
EXCEL: POWER QUERY FOR BEGINNERS Import Several Files in one Step

Figure 5-10: This data can now be loaded into Excel

Click on the button Close & Load.

Figure 5-11: The content of the four Excel files in one list

Now you can continue editing the data with the standard Excel tools. For example, you can
use a PivotTable to determine how much revenue you have generated with each material.

50
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

6 EXTRACTING DATA FROM


AN EXCEL SPREADSHEET
In this chapter, you will learn how to extract data from a very complex Excel spreadsheet.
The workbook containing the table is over 60 MB in size. The task is to evaluate some of
the data with a Pivottable. Since each action takes several seconds, it makes sense to use
Power Query to fetch only the data you need from the source.

6.1 THE COMPLEX SPREADSHEET


The file is about 60 MB in size. It contains 317,559 rows and 41 columns to be analyzed.
Our goal is to use Power Query to create a new file and only filter the data needed for the
analysis. (File: Data_300000.xlsx)

Figure 6-1: This is the data to be imported

However, you only want to evaluate the Date, Region, Distributor, Weight, Product_extern
and Supply_by fields.

In addition, you need two calculated columns. You want to calculate the total costs from
columns E to K (Cost_1 to Cost_7) as well as the difference between the fields Order
and Supply.

6.2 EXTRACTING PART OF THE DATA


Start by editing the table of more than 300,000 rows and 41 columns with Power Query.

Go to a new empty workbook.


Choose Data / Get & Transform Data / Get Data / From File / From Workbook.
Select the file Data_300000.xlsx and click the Import button.

51
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

There are two worksheets in the sample workbook. Select the Report_LOG sheet
in the Navigator window.

Figure 6-2: Select the spreadsheet you want to import data from

Click the Edit button to customize the data in Power Query.

Info: An Excel table can contain a maximum of 1048576 rows and 16384 columns.

Figure 6-3: The data in Power Query

52
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

6.3 CLEANING UP THE DATA


To get started, the data needs to be cleaned up. Some lines need to be deleted, the headers
need to be defined and data types assignments are needed.

First remove the first five lines from the Home / Reduce Rows / Remove Columns /
Remove Top Rows command.

Figure 6-4: Remove this many rows

Next, use the Use First Rows as Headers command to create the correct headings.
Assign the appropriate data types to the columns. To do this, click on the data
type symbol of each column and select the desired type.
The column Date should have the data type Date.
The columns Cost_1 to Cost_7, Order, Supply and Weight are given the data
type Decimal Number.

Figure 6-5: After assigning the correct data types

6.4 CREATE CALCULATIONS IN NEW COLUMNS


In the next step you want to calculate the costs. The costs are distributed across seven
columns, so you have to sum the values.

53
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

Select the columns Cost_1 to Cost_7.


Activate the tab Add Column and click on Standard.

Figure 6-6: The standard calulations

Select the function Add.

The result is a new column that is the sum of the selected columns.

Figure 6-7: The new column containing the sums

Double click the column to rename it to Cost.

In the second calculation, you want to determine how high the loss is in deliveries. To do
this, calculate the difference between the Order and Supply fields.

Activate the tab Add Column and click on Custom Column.


Enter Shortage as the new column name.

54
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

Insert this formula for the calculation:


=[Order]-[Supply]

Figure 6-8: The second calculation

Confirm with OK.


Change the data type of the column to Decimal Number.

Figure 6-9: The Shortage per delivery is calculated

Now you just remove the columns you don’t need. You can remove a column by right-
clicking and using the Remove command.

55
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

Remove all columns except Date, Region, Distributor, Product_external, Supply_


by, and Weight. Of course, you’ll want to keep the two new columns Cost and
Shortage.

Info: In this step you only delete the columns in Power Query. The original Excel spreadsheet
is not touched.

You can also highlight the columns listed above and use the Remove Other Columns
command in the context menu.

Figure 6-10: Only these columns will be imported

This completes the processing of your data in Power Query. You have reduced the number
of columns from 41 to six. Of course, you could have done the calculations in the two
additional columns in Excel as well. But this would have required you to import all nine
Cost columns.

6.5 TRANSFERRING THE DATA TO EXCEL


Now you are just a click away from transferring the data to Excel.

Click the Close & Load button on the Home tab and watch Excel import the
records.

Now you can start to evaluate this data.

Save your work and look at the file size.

56
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

Figure 6-11: You can see a clear difference in the file size before and after
importing the data

The file edited by Power Query is only a fraction of the size of the original file.

6.6 ANALYZING THE DATA WITH PIVOTTABLES


In the first step, you want to know how many kilograms have been delivered per hauler.
You have the data you need in the columns Supply_by and Weight.

This task calls for a pivot table.

Click in your dynamic table and select Design / Summarize with Pivot Table or
Insert / PivotTable.

The dynamic table is called Report_LOG. This will be the basis of your PivotTable.

Figure 6-12: Creating a pivot table

Confirm with OK.

Drag the Weight field into the Values ​​area.

57
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

If Excel does not calculate the sum, right-click on the result and choose Summarize Values​​
By / Sum.

Mark the cell with the sum and assign the cell the number format with thousands
separators. Set the number of decimal places to zero.

Now you have summarized the total weight of the goods you have sent in a single number.

Drag the field Supply_by into the Rows area.

Figure 6-13: Each supplier has a total weight

You can see immediately which freight forwarder has delivered the greatest weight.

In the last step you want to sort by weight.

Right click any value in the Sum_of_Weight column and select Sort / Sort Largest
To Smallest.

You may also want to change the layout and formatting of the table using the Design tab.

58
EXCEL: POWER QUERY FOR BEGINNERS Extracting data from an Excel spreadsheet

Figure 6-14: The result: The list of freight forwarders and the weight of
goods each delivered

Now we can go on to create more pivot tables.

59
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

7 MERGING MULTIPLE
SPREADSHEETS
In this chapter you will learn how to merge several tables together.
Error! Use the Home tab to apply Überschrift 1 to
the text that you want to appear here.
In this example we transfer four tables from a workbook to Power Query. The example

Editing cell content


illustrates the two commands Append Queries as New and Append Queries. .

We also demonstrate that when merging tables, the order of the columns in Excel does not
matter. The reason
In most cases, is that
imported Power
data has Query
to be editedis(orbased on column
»transformed«) titles.
before In addition,
it can it does
be analyzed. not in
The tools
matter if one table has more columns than another table.
Power Query let you split, merge, replace, and cleanse cell content.

 Open
Openthethe Chapter4_1.csv.
filefile Chapter 7.xlsx.

This chapter will introduce you to a set of commands that allow you to edit your data efficiently.

7.1 THE WORKBOOK AND ITS FOUR WORKSHEETS


The example file contains four worksheets.. 2017_12, 2018_01, 2018_02 und Late_2018_03.

Figure 0-1: There are several problems with this table

The No_Material column contains the material number and name together in a single cell. Some of the
names of the sales representatives in the Rep_Name column have digits in them. The column Cust_City
contains the customer name and location separated by a hyphen.

Power Query helps you deal with these problems without having to enter a single formula. But before we
get started, we’ll have a look at how to move data from an open Excel spreadsheet to Power Query.

Figure 7-1: The four worksheets in the Workbook


Bringing Excel data to Power Query
Themake
To steps to getexample
the data froma Excel
little into
more Power Query are
interesting weconverting the table
added a small to a dynamic table, renaming
pitfall:
it, and then passing it to Power Query.
On the worksheets 2018_01, 2018_02 and LATE_2018_03 there is a column that does
not yet Click
exist anywhere
on the worksheet
in the table2017_12.
and press [Ctrl] + [T].
Make sure that Excel automatically included all the cells in your table in the Create Table window.

60
39
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

It sometimes happens in practice that users change the table layout. If you only work with
copy and paste, this can easily create problems.

The Base Price column does not appear in all the tables.

Figure 7-2: The pitfall

7.1.1 TRANSFERRING THE FIRST TABLE TO POWER QUERY

Now let’s transfer the content of the first table to Power Query. Power Query only recognizes
dynamic tables, so the first step is to convert the table to a dynamic table.

Activate the worksheet 2017_12 and click any cell in the table.
Press [Ctrl] + [T], check the cells Excel finds, correct them if necessary, and confirm
with OK.

Figure 7-3: Creating a dynamic table from the first spreadsheet

Excel now converts the data into a dynamic table. It is named Table1 by default. This name
is not very meaningful, which matters because it will later be used as the name for the query.

To change the name of the table, activate the Design tab.


Enter a name in the Table Name field, for example Y2017_12. Confirm with [].

61
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

Figure 7-4: Renaming the dynamic table

Info: The table names must not start with a number or contain spaces. You also need to
complete the entry with [].

This table is now ready for editing in Power Query.

Activate the Data tab and click the From Table/Range button in the Get &
Transform Data area.

Figure 7-5: transferring the dynamic table to Power Query

The table is displayed in the query editor, and you can see the query name in the Navigator
Pane on the left. When there are multiple queries in the current workbook this area is very
important, because it displays a complete list.

Figure 7-6: The first table in Power Query

62
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

For the time being no changes to the data structure are needed, since you have not merged
all the data yet. The structure changes come at the very end.

To get the second table into the editor, you must now move the first query to Excel. That
is the only way to get back to Excel.

Select the command Home / Close & Load To.

Figure 7-7: Transfering the data to Excel

All the original data is in Excel. There is no need to paste another copy into the current
workbook. It would increase the file size unnecessarily.

Choose the option Only Create Connections.

Figure 7-8: Creating a connection

When you click the OK button, you will be returned to Excel.

7.1.2 TRANSFERRING THE REMAINING TABLES TO POWER QUERY

Your first query is listed on the right side of the screen. Since it’s just a connection, you
will not see any other information about the table.

63
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

Go to the worksheet 2018_01.


Create a dynamic table from this table as described above.
Give it the name Y2016_01 and transfer it to Power Query.
Create a connection only. Then bring the third table to Power Query the same way.
It is important that you also create a connection to Excel for the third query. If
you did not do this, the query will be inserted later in Excel. But there is no need
for the query data in Excel, since this data is already there as a table.

Figure 7-9: All three queries are connections only

The contents of the Late_2018_03 worksheet will be added later.

Double-click a query to open the Query Editor again.

7.2 APPENDING SEVERAL QUERIES TO EACH OTHER


On the left of the Query Editor you see all three queries, which are now combined in a
new query.

Select query Y2018_02 in the navigation area.


Select the command Home / Combine / Append Queries / Append Queries as
New.

64
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

Figure 7-10: The Append Queries command

The query that you have currently selected is already selected and that means it is the
primary table.

Figure 7-11: Merging several queries

Since there are three queries in this example, you need the Three or more tables
option.

All available queries are visible on the left in the list box Available table(s).

Info: If »Y2018_2« is first in the field Tables to append, then its data is inserted first and
the column Base Price is in the fifth position. If the field Tables to append contains the
query »Y2017_12«, then the Base Price column is at the last position.

The query data is merged together in the order of the tables in the Tables to append field.
But because Power Query also provides you with the Sort command and the ability to
move columns, the order of the queries does not matter.

65
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

Figure 7-12: These queries will be merged to create a new one

Confirm with OK.

You can already see the new query in the pane on the left. It has been named Append1.
The Base Price column is in the fifth position. Up to line 160, you can see the contents
of query Y2018_2. From line 161, you see the contents of the query Y2018_1. From line
186, you see the contents of the query Y2017_12. Since the Base Price column does not
exist in query Y2017_12, Power Query has entered the value null there.

You will change this later.

Figure 7-13: The new query

Change the name of the query to Sales Volume.

Figure 7-14: Renaming the new query

66
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

7.2.1 MODIFYING THE NEW QUERY

First, the null values should be replaced by 0 in the Base Price column. Then the data
types are adjusted for all columns.

Click in the Base Price column.


Select the Home / Replace Values command.
​​ The command can also be found in
the context menu of the right mouse button.
Enter the word null in the first field, Value To Find.

Info: Pay attention to capitalization on the Value To Find field. If you enter the word
NULL, a warning appears to the right of the field. It says that this word is not found
in the active column.

Enter 0 in the Replace With field.

Figure 7-15: Replacing values in the active column

Confirm with OK.

Now there are numbers in all cells of the Base Price column.

Figure 7-16: The Base Price column after the change

Assign the data type Date to the Date column.


The Base Price, Net Price, Volume and Net Sales columns are given the data type
Decimal Number.

67
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

In the last step we remove the columns.

Delete the columns Mat No and Cat no. The quickest way to do this is to highlight
the column and press the [Del] key.


Figure 7-17: Three tables merged into one

The data is now ready to be edited in Excel.

7.2.2 QUERY DEPENDENCIES

Power Query gives you a good overview of your queries and their dependencies on each other.

Choose the command View / Query Dependencies.


Figure 7-18: Overview of the queries and their dependencies

68
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

7.3 WORKING WITH THE CONSOLIDATED TABLE


The next step is to move the consolidated table to a new worksheet.

Select the command Home / Close & Load.

Figure 7-19: The table in Excel

Assign the data type Currency to the Base Price, Net Price and Net Sales columns.
Rename the worksheet to Sales_Volume.

7.4 INSERTING ANOTHER TABLE


We continue now with the import of worksheets into a query.

The next step is to insert another table into the query Sales. This requires several steps.

Rename the sheet Late_2018_03 to 2018_3.


Make the table a dynamic table and name it Y2018_3.
Transfer the dynamic table to Power Query and select Only Create Connection
from the command Home / Close & Load / Close & Load To.

If you do not perform the last step of returning to Excel as a connection, the data will be
passed to Excel as a table. This is not necessary because this data is already available as a table.

• Double-click on a query.
The new query Y2018_3 has now been transferred.

69
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

Figure 7-20: The new query is now available

The next step is to integrate the new query in the existing query Sales Volume.

Select the query Sales Volume.


Click the gear next to the step Source in the Query Settings pane on the right.

If you do not see the pane, activate the View tab and select the command Query Settings.

Figure 7-21: Die Quelle der Abfrage Umsätze erweitern

In the field Available table(s) on the left, select the new table Y2018_03.
Click the Add button.

This appends all data from query Y2018_3 to the Sales Volume query. If you want to see
this new data at the top, follow these steps:

Select query Y2018_3 in the Tables to append area and click on the button
until the new query is at the top.

70
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

Figure 7-22: Inserting the new query

Confirm with OK.


In the Query Settings area, click on the last step, Removed Columns.

Figure 7-23: The new query contains all tables

In the status bar you can see the new number of lines. Now only the new data has to be
transferred to Excel.

Select Home / Close & Load.

In the Queries & Connections area, you can see the new number of rows.

71
EXCEL: POWER QUERY FOR BEGINNERS Merging multiple Spreadsheets

7.5 STORING QUERIES IN FOLDERS


The second chapter mentioned that you can store your queries in a structured way in folders.

Figure 7-24: The five queries without folders

You could move the four connection queries to the sources into a folder called Data Source.
And the result query can be stored, for example, in the folder Result. Use the right mouse
button for all these commands.

Figure 7-25: The five queries in folders

The Other Queries folder appears automatically and cannot be deleted. New queries
automatically land in this folder.

72
EXCEL: POWER QUERY FOR BEGINNERS Index

INDEX
A Q
Advanced Editor 9, 19, 43, 73 Query Dependencies 68, 74
all files from a folder 73
R
Append Queries 60, 64, 65, 73
APPLIED STEPS 12, 14, 17, 18, 73 Rename 37, 39, 69, 73
Replace values 74
C
S
content 7, 9, 12, 29, 33, 35, 39, 41, 49, 50, 61
Copy query 73 Split 9, 36, 39, 73, 74
Create Table 33, 73 Split Column by Delimiter 74
Split columns 74
D Split text 74
Delimiter 11, 39, 73, 74
T
E table 7, 15, 17, 20, 21, 22, 23, 24, 25, 26, 27, 28,
Extension 47, 73 30, 31, 32, 33, 34, 35, 36, 42, 43, 48, 49, 51,
52, 57, 58, 60, 61, 62, 63, 64, 65, 69, 70
F
Table
filter 8, 30, 31, 41, 47, 51 primary 74
Filter
Extension 47
folder 10, 29, 45, 46, 47, 72, 73
From Table/Range 34, 62, 73

G
gear 14, 18, 19, 70, 73

I
import 6, 7, 10, 17, 19, 45, 46, 47, 48, 52, 56, 69

M
Multiple Spreadsheets 73

O
Only Create Connections 63, 73

P
PowerPivot 6, 21, 22, 23, 24, 74
primary 65, 74
Primary Table 74

73

You might also like