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

Master Power Query Power Query – Solutions Guide

Table of Contents
Solutions to Common Date Problems
Calculating Ages in Years ..........................................................................................................................3
Calculating Time Served in Days................................................................................................................4
Calculating Days Till Warranty Expiration.................................................................................................5
Creating Dates from Multiple Columns .....................................................................................................6
Creating Dates with Missing Days .............................................................................................................7
Creating Dates Using Custom Columns .....................................................................................................8
Deriving Dates from Words .......................................................................................................................9
Correcting Date Formats from Other Regions .........................................................................................10
Create a Calendar Table From Start to End Date ....................................................................................11
Solutions to Common Time Calculations
Calculating Hours Worked (spanning days) ............................................................................................19
Create Date/Time from Separate Values ................................................................................................20
Helpful Power Query Tricks
The Hidden Table Method – Keep Your Source Formatting ....................................................................23
How to Refer Back to Previous Steps .......................................................................................................26
How to Adjust FILTER & Conditional Column Formulas – Use Dynamic References ...............................28
Create a Template With Power Query ....................................................................................................31
Solutions to Appending Data Challenges
Pivot Table from Multiple Excel Tables ...................................................................................................35
Combine Data From Multiple Workbooks ...............................................................................................40
Combine ALL Excel Files in a Folder .........................................................................................................42
Adjust Folder Path from Local to SharePoint Drive .................................................................................46
Combine All Sheets in a File .....................................................................................................................48
Consolidate Data From Multiple Sheets in the Current Workbook .........................................................52
How to Select File Path with Power Query Parameters ..........................................................................56
Manage the File Path from an Excel Cell .................................................................................................58
Import from Folder & Clean Headers ......................................................................................................61
How to Append All Sheets when Data Starts from Different Rows .........................................................63
Append Sheets and Get Field Name from a Cell Outside the Table ........................................................65
Unpivot & Consolidate Data from Multiple Sheets .................................................................................68
Solutions to Common Data Analysis Problems
How to Create Buckets for your Data ......................................................................................................73
Master Power Query Power Query – Solutions Guide

Changing Source File Location from Local to SharePoint ........................................................................76


Messy Data from Multiple Rows to One Row – Creating a Proper Data Set ..........................................78
Search and Replace Bulk Values ..............................................................................................................80
Calculate Value Difference to Previous Row – Merge a Query with Itself ..............................................83
Approximate Match Lookup with Merge ................................................................................................85
Create a Report Based on Multiple Excel Parameters.............................................................................87
Find Mismatches In Data .........................................................................................................................90
Nested Rank with Power Query – Rank in Each Group ...........................................................................94
Assign Unique Numbers to a Group ........................................................................................................96
Unpivot Data With Multiple Headers ......................................................................................................98
Pivot Data without Anchor Columns .................................................................................................... 102
Learn More
More Resources .................................................................................................................................... 107

Copyright © 2020 Leila Gharani


Master Power Query Power Query – Solutions Guide

Solutions Book for Master Excel Power Query


This detailed manual is accompanying documentation for my online Master Excel Power Query:
Beginner to Advanced (including M) course on XelPlus.com/courses. Please do not reproduce or
transmit in any form without permission.
We (XelPlus e.U.) have taken every effort to ensure the accuracy of this manual. In case you discover
any discrepancies, please send us a quick email to [email protected].

Copyright © 2020 Leila Gharani


Master Power Query Power Query – Solutions Guide

Availability of Power Query


Power Query is natively integrated in several Microsoft products, including the following.

Microsoft Power Query enables Excel users to import data from a wide range of data sources
Excel into Excel for analytics and visualizations.
Starting with Excel 2016, Power Query capabilities are natively integrated and can be
found under the “Get & Transform” section of the Data tab in the Excel Desktop
ribbon.
Excel 2010 and 2013 users can also leverage Power Query by installing the Microsoft
Power Query for Excel add-in.

Microsoft Power Query enables data analysts and report authors to connect and transform data
Power BI as part of creating Power BI reports using Power BI Desktop.

Microsoft SQL Business Intelligence Developers can create Azure Analysis Services and SQL Server
Server Data Analysis Services tabular models using SQL Server Data Tools for Visual Studio. Within
Tools for this experience, users can leverage Power Query to access and reshape data as part
Visual Studio of defining tabular models.

Common Common Data Service lets you securely store and manage data that's used by
Data Service business applications. Data within Common Data Service is stored within a set of
entities. An entity is a set of records used to store data, similar to how a table stores
data within a database.
Common Data Service includes a base set of standard entities that cover typical
scenarios, but you can also create custom entities specific to your organization and
populate them with data using Power Query. App makers can then use Power Apps
to build rich applications using this data.

Copyright © 2020 Leila Gharani


Master Power Query Power Query – Solutions Guide

About Leila Gharani


Leila Gharani is a Microsoft MVP & a bestselling online course instructor. She runs XelPlus.com an
spreadsheet resource site to help people gain the knowledge they need so they can create useful tools,
solve problems and get more done.
Her background is Masters in Economics, Economist, Consultant, Oracle HFM Accounting Systems Expert
& Project Manager. Find out more here.

Copyright © 2020 Leila Gharani


Master Power Query Power Query – Solutions Guide

The Accompanying Files


The examples shown in this manual are taken from the Excel files available inside the online course.
All files are available as a zip file.

Copyright © 2020 Leila Gharani


Solutions to
Common Date
Problems
Power Query Solutions to Common Date Problems

CALCULATING AGES IN YEARS


Load a table that includes dates into Power Query.

1. Select the Date column and convert to a Date data type (if necessary)

2. Select Add Column (tab) → From Date & Time (group) → Date → Age.

3. Select Duration → Total Years.

4. Select From From Number (group) → Rounding → Round Down.

Copyright © 2020 Leila Gharani 3|Page


Power Query Solutions to Common Date Problems

CALCULATING TIME SERVED IN DAYS


Load a table that includes dates into Power Query.

1. Select the Date column and convert to a Date data type (if necessary)

2. Select Add Column (tab) → From Date & Time (group) → Date → Age.

3. Select Duration → Total Days.

4|Page Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

CALCULATING DAYS TILL WARRANTY EXPIRATION


Load a table that includes dates into Power Query.

1. Select the Date column and convert to a Date data type (if necessary)

2. Select Add Column (tab) → From Date & Time (group) → Date → Age.

3. Select Duration → Total Days.

4. Select From From Number (group) → Scientific → Absolute Value.

Copyright © 2020 Leila Gharani 5|Page


Power Query Solutions to Common Date Problems

CREATING DATES FROM MULTIPLE COLUMNS


Load a table that includes the year, month, and day information into Power Query.

1. Select the Year, Month, and Day columns.

2. Select Add Column (tab) → From Text (group) → Merge Columns. Define the separator
(comma) and name the new column (“Date”).

3. Select Date → Parse.

6|Page Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

CREATING DATES WITH MISSING DAYS


Load a table that includes years and months into Power Query.

1. Select the Year and Month columns.

2. Select Add Column (tab) → From Text (group) → Merge Columns. Define the separator
(comma) and name the new column (“First of Month”).

3. Select Date → Parse.

Copyright © 2020 Leila Gharani 7|Page


Power Query Solutions to Common Date Problems

CREATING DATES USING CUSTOM COLUMNS


Open Power Query with a table containing columns labeled Year, Month, and Day.

1. Select Add Column (tab) → General (group) → Custom Column.

2. In the Custom Column dialog box, the new column will be named “Custom Date” and the
formula will be as follows:

= #date([Year],[Month],[Day])
or
= #date([Year],[Month],1)

NOTE: The second version of the formula can be used if you want all dates to be on the first of each
month.

3. Format the newly created dates to a Date data type.

8|Page Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

DERIVING DATES FROM WORDS


Suppose we have months listed as words (i.e. Jan…Dec) and we need to create usable dates. Select the
list of months and load into Power Query.
We don’t have a direct way to convert these words to dates, so we have to “trick” Power Query into
thinking these are dates.
We can either add a year to the end of each word or add a day to the beginning of each word.

1. Select the column of month names and click Add Column (tab) → From Text (group) → Format
→ Add Prefix.

2. In the Prefix dialog box, add “1,” to the Value field.

3. Select Date → Parse.

Copyright © 2020 Leila Gharani 9|Page


Power Query Solutions to Common Date Problems

CORRECTING DATE FORMATS FROM OTHER REGIONS


Load a table that includes Dates that differ in format from your own into Power Query.

1. Select the Foreign Date column.

2. Select the button next to the “Foreign Date” heading and select “Using Locale…”

3. In the Change Type with Locale dialog box, set the Data Type to “Date” and the Locale to the
choice that best represents the country the data originated, such as Germany (Germany), and
click OK.

10 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

CREATE A CALENDAR TABLE FROM START TO END DATE


Issues / Requirements:

• We have an Excel Table named “TDates” which contains a list of dates and prices that denote
each time a price change occurred.

• Create a comprehensive list of dates that start from the earliest date in the table through the
latest date in the table.

• Each date should have the price that applies to that date.

Solution Steps:
Load the Date to a Query

1. Load the Excel Table into Power Query as a Table.

2. Update the Dates column to a Date data type.

3. Close & Load the results as a Connection Only query.

Creating a Calendar Table – Method 1

1. Select Data (tab) → Get & Transform (group) → Get Data → From Other Sources → Blank
Query.

2. In the Formula Bar, type the following:

=List.Dates(#date(2020, 4, 1), 30, #duration(1,0,0,0) )

We are delivered a list of dates from April 1, 2020 through April 30, 2020.

Copyright © 2020 Leila Gharani 11 | P a g e


Power Query Solutions to Common Date Problems

3. Select List Tools – Transform (tab) → Convert (group) → To Table to convert the list to a table.

4. Rename Column1 to “Date”.

5. Change the Date column to a Date data type.

6. Add a column to hold extracted years by selecting Add Column (tab) → From Date & Time →
Year → Year.

7. Add a column to hold extracted month names by selecting Add Column (tab) → From Date &
Time → Month → Name of Month.

8. Name the query “Calendar_V1”.

9. Close & Load the results as a Connection Only query.

The results are as follows:

12 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

Creating a Calendar Table – Method 2

1. Select Data (tab) → Get & Transform (group) → Get Data → From Other Sources → Blank
Query.

2. In the Formula Bar, type the following:

={#date(2020, 4, 1) .. #date(2020, 4, 30) }

We are presented with an error stating that lists cannot be built from dates using the “..” syntax.

3. In the Formula Bar, update the formula with the following:

={Number.From(#date(2020, 4, 1) ) .. Number.From(#date(2020, 4, 30) )}

We are delivered a list of values that represent the dates from April 1, 2020 through April 30, 2020.

4. Select List Tools – Transform (tab) → Convert (group) → To Table to convert the list to a table.

Copyright © 2020 Leila Gharani 13 | P a g e


Power Query Solutions to Common Date Problems

5. Rename Column1 to “Date”.

6. Change the Date column to a Date data type.

7. Name the query “Calendar_V2”.

8. Close & Load the results as a Connection Only query.

The results are as follows:

Determining the Extents of the Data’s Date Range


The previous example both have the start and end dates hard-coded in the formula.
We need this list to be dynamic based on the oldest and newest dates in the data. This is a fairly simple
process.

1. Load the Excel Table into Power Query as a Table.

2. Name the query “MinMaxDate”.

3. Remove the Price column.

4. For the Date column, select the Filter → Date Filters → Custom Filter.

14 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

5. In the Filter Rows dialog box, set the parameters as shown in the following illustration.

6. As a precautionary step, remove the duplicates.

7. Sort the table in Ascending order by Date.

The results are as follows:

Building the Calendar Table from Table References


Now that we have determined the earliest and latest dates in the data, we can use those to build our
calendar table.

1. Select Data (tab) → Get & Transform (group) → Get Data → From Other Sources → Blank
Query.

2. In the Formula Bar, update the formula with the following:

={Number.From(MinMaxDates[Date]{0} ) .. Number.From(MinMaxDates[Date]{1} ) }

We are delivered a list of values that represent the dates from the earliest date in the data through the
latest date in the data.

3. Select List Tools – Transform (tab) → Convert (group) → To Table to convert the list to a table.

Copyright © 2020 Leila Gharani 15 | P a g e


Power Query Solutions to Common Date Problems

4. Change the Column1 column to a Date data type.

5. Rename the column to “Date”.

1. Merge this table with the TDates table by selecting Home (tab) → Combine (group) → Merge
Queries → Merge Queries as New.

2. In the Merge dialog box, set the parameters shown in the following illustration.

3. Expand the column of nested tables to include the Price field.

4. Sort the table in Ascending order by Date.

5. Fill Down the Price column to replace nulls with prices.

6. Close & Load the results to an Excel Table.

16 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Date Problems

The results are as follows:

Copyright © 2020 Leila Gharani 17 | P a g e


Solutions to
Common Time
Calculations
Power Query Solutions to Common Time Calculations

CALCULATING HOURS WORKED (SPANNING DAYS)


Load a table that includes Start Times and End Times into Power Query.

1. Select the End Time column, press CTRL, and select Start Time.

2. Select Add Column (tab) → From Date & Time (group) → Time → Subtract. Remember, the
result is returned as a Duration data type read as Days.Hours:Minutes:Seconds.

3. Select Time → “Hours” to get the time rounded down to the nearest hour. Select Time → Total
Hours to get a precise number of hours.

Copyright © 2020 Leila Gharani 19 | P a g e


Power Query Solutions to Common Time Calculations

CREATE DATE/TIME FROM SEPARATE VALUES


Load a table that includes Days and Time into Power Query.

1. Select the Day column, press CTRL, and select the Time column.

2. Select Add Column (tab) → From Date & Time (group) → Time → Combine Date and Time.

20 | P a g e Copyright © 2020 Leila Gharani


Helpful Power
Query Tricks
Power Query Helpful Power Query Tricks

THE HIDDEN TABLE METHOD – KEEP YOUR SOURCE FORMATTING


The benefits of this tactic are:

• access to all the features of Excel Tables, such as the automatic inclusion of new data.
• the ability to use a named range as your data source.
• the ability to retain the formatting of the source data.

NOTE: Merged Cells are not allowed in Excel Tables. If you convert a plain table to an Excel Table, the
merge feature will be removed. We will restore the merged look with a different feature.

Step 1: Convert the Plain Table to an Excel Table

1. Select the data range and upgrade to an Excel Table. This can be done via:

• CTRL-T keyboard shortcut


• Home (tab) → Styles (group) → Format as Table
• Insert (tab) → Tables (group) → Table

2. In the Create Table dialog box, verify proper range selection and ensure the “My table has
headers” option is NOT selected.

The result is a less-than-optimal table.

Step 2: Adjusting the Excel Table Before Import into Power Query
The Excel Table requires a few modifications before we import it into Power Query.

Copyright © 2020 Leila Gharani 23 | P a g e


Power Query Helpful Power Query Tricks

4. Remove the automatically applied table layout by selecting Table Design (tab) → Table Styles
(group) → bottom scroll button → Clear.

5. Give the table a proper name, like “NiceTable”, by selecting Table Design (tab) → Properties
(group) → Table Name.

6. Hide the “bad” headers by selecting Table Design (tab) → Table Style Options (group) → Header
Row.

7. If you had any merged cells (i.e. titles), you can restore the merged look by selecting the cells you
wish to “merge”, press CTRL-1 to open the Format Cells dialog box, and select Alignment (tab)
→ Text Alignment (group) → Horizontal → Center Across Selection.

Step 3: Sending the Table to Power Query


To load the table into Power Query:

1. Click anywhere in the data and select Data (tab) → Get & Transform Data (group) → From
Table/Range.

2. Rename the query from “NiceTable” to “NiceReport”.

24 | P a g e Copyright © 2020 Leila Gharani


Power Query Helpful Power Query Tricks

Step 4: Processing the Query

5. If any unnecessary header promotions or data typing was automatically performed, remove
those steps from the Applied Steps list.

6. Remove the first row in the data:

a. select Home (tab) → Reduce Rows (group) → Remove Rows → Remove Top Rows
b. in the Remove Top Rows dialog box, enter a “1” in the Number of Rows option

7. Promote the first row as to a header by selecting Home (tab) → Transform (group) → Use First
Row as Headers.

8. Rename the headers to something more meaningful.

9. Repeat the category labels by selecting Transform (tab) → Any Column (group) → Fill → Down.

At this point, we can Close & Load this to a new table, a Pivot Table/Chart, or into our Data Model.

Copyright © 2020 Leila Gharani 25 | P a g e


Power Query Helpful Power Query Tricks

HOW TO REFER BACK TO PREVIOUS STEPS


Objectives:

• Calculate the average price across all sales reps?

• Determine who sold below the average price?

Solution Steps:

1. Click in the data and select Data (tab) → Get & Transform (group) → From Table/Range.

2. Name the query “BelowAverage”.

3. Update the “Changed Type” step to have the Date column set as a Date data type.

We want to calculate the average price across all values in the “Price $” column, but we are unable to
use the Average feature from Add Column → Statistics.

4. Select the “Price $” column and click Transform (tab) → From Number (group) → Statistics →
Average.

This produces a single value as a result.

5. Rename the step “CalculateAverage”.

We want to retain this value, but we need to apply it to the data from the previous step.

6. To restore the data from the previous step, click the button to the left of the Formula Bar to
insert a new step at the end of the query steps list.

26 | P a g e Copyright © 2020 Leila Gharani


Power Query Helpful Power Query Tricks

7. Enter the following formula to point to the previous step named “Changed Type”.

= #”Changed Type”

NOTE: If the step name does not contain spaces, you can eliminate the # and quotes.

= ChangedType

8. Rename the newly inserted step “GoBack”.

9. Create a Custom Column by selecting Add Column (tab) → General (tab) → Custom Column.

10. Name the new column “Difference”.

11. The Custom Column formula will be as follows:

= [Price $] - CalculatedAverage

12. Set the data type for Difference to Currency.

13. To determine the Sales Reps who sold below the Difference, filter the Difference column for
items below 0.

14. Sort the Sales Rep column in ascending order.

Copyright © 2020 Leila Gharani 27 | P a g e


Power Query Helpful Power Query Tricks

HOW TO ADJUST FILTER & CONDITIONAL COLUMN FORMULAS –


USE DYNAMIC REFERENCES
Objective:
Obtain a unique list of Sales Reps who sold 8 dollars below the maximum price.
Solution Steps:

1. Click in the data and select Data (tab) → Get & Transform (group) → From Table/Range.

2. Name the query “NameReport”.

3. Delete the Date column.

4. Select the “Price $” column and click Transform (tab) → From Number (group) → Statistics →
Maximum.

This produces a single value as a result.

5. Rename the step “CalcMax”.

We want to retain this value, but we need to apply it to the data from the previous step.

6. To restore the data from the previous step, click the button to the left of the Formula Bar to
insert a new step at the end of the query steps list.

7. Enter the following formula to point to the previous step named “Changed Type”.

= #”Removed Columns”

28 | P a g e Copyright © 2020 Leila Gharani


Power Query Helpful Power Query Tricks

NOTE: If the step name does not contain spaces, you can eliminate the # and quotes.

= RemovedColumns

8. Rename the newly inserted step “GetTableBack”.

At this point, we could create a custom column that calculates the difference between each “Price $”
and the result of the CalcMax step then use the FILTER option to reduce the list.
Since we do not need to retain the “Price $” in the final result, we will work with the FILTER feature
directly.

9. Select the “Sales $” column and filter for Less Than 8.

Since we can’t reference query steps in the Filter Rows dialog box, the “8” is going to act as a
placeholder.

10. Update the formula to the following:

= Table.SelectRows(GetTableBack, each [#"Price $"] < CalcMax - 8)

Copyright © 2020 Leila Gharani 29 | P a g e


Power Query Helpful Power Query Tricks

NOTE: When you directly modify a step in the Formula Bar, if that step contained parameters that could
be updated via the gear icon , you will lose the ability to perform updates in this manner. To restore
the gear icon , remove the original modification, make the adjustments using the gear icon , then
replace the adjustments.

11. Remove the “Price $” column.

12. Remove the duplicates from the Sales Rep column (future-proofing step).

13. Sort the Sales Rep list in ascending order.

30 | P a g e Copyright © 2020 Leila Gharani


Power Query Helpful Power Query Tricks

CREATE A TEMPLATE WITH POWER QUERY


Objective:

• Using a supplied list of names and dates, create a template that repeats the dates for each name
in the list.

• Each name should have the ability to enter a start date and end date for each day in the list of
dates.

Solution Steps:

1. Click a cell in the list of dates and select Data (tab) → Get & Transform (group) → From
Table/Range.

2. In the Create Table dialog box, click OK.

3. Change the Dates data type to Date.

4. Name the query ProjectDates. Remember this name; it will be referenced towards the end of this
solution.

5. Close & Load back to Excel as a Connection Only query.

Copyright © 2020 Leila Gharani 31 | P a g e


Power Query Helpful Power Query Tricks

6. Click a cell in the list of names and select Data (tab) → Get & Transform (group) → From
Table/Range.

7. In the Create Table dialog box, click OK.

8. Name the query TimeSheets.

9. Bring in the dates with the list of names by selecting Add Column (tab) → Custom Column.

10. In the Custom Column dialog box, name the new column Dates.

We need to bring in the list of dates (an entire table) for each row in the list of names.

11. For the custom formula, enter the following formula (a reference to another query):

= ProjectDates

12. Click OK.

This generates a nested table for each row in the Names column.

13. To display the complete list of dates for each name, click the Expand Columns button in the
upper-right of the Dates column.

14. Deselect the “Use original column name as prefix” option and click OK.

15. Rename the Dates.1 column to Dates.

16. Change the data type for the Date column to Date.

32 | P a g e Copyright © 2020 Leila Gharani


Power Query Helpful Power Query Tricks

We need to remove the redundant name entries from the Name column. We have a constant that the
first date for each employee is 6/1/2020. We will create a Conditional Column that tests for the
presence of this day and repeats the Name if it is a match. If it is not a match, it will leave the cell
empty.

17. Select Add Column (tab) → General (group) → Conditional Column.

18. In the Add Conditional Column dialog box, enter the following parameters:

Parameter Entry
New column name Employee Name
Column Name Dates
Operator Equals
Value 6/1/2020
Output Names
Else null

19. Change the data type for “Employee Name” to Text.

20. Select the “Employee Name”, hold down CTRL, select the Dates column.

21. Right-click a selected column heading and select Remove Other Columns.

22. Close & Load the results back to Excel as a table.

Copyright © 2020 Leila Gharani 33 | P a g e


Solutions to
Appending Data
Challenges
Power Query Solutions to Appending Data Challenges

PIVOT TABLE FROM MULTIPLE EXCEL TABLES


Requirements / Issues:

• Create a report of Customers and Sales in descending order by Sales.

• Create a report of quantity sold by Article in descending order by Quantity.

• Main table with sales (fact table) is loaded as an Excel Table named “TableSales”.

• Supplemental table with Article Descriptions and Colors named “MasterArticle”.

• Supplemental table with Customer Names named “MasterCustomer”.

Solution Steps:
Creating the Table Relationships

1. Select the TableSales table and click Data (tab) → Data Tools (group) → Relationships.

2. In the Manage Relationships dialog box, click New…

3. In the Create Relationship dialog box, set the parameters shown in the following illustration.

4. In the Manage Relationships dialog box, click New…

5. In the Create Relationship dialog box, set the parameters shown in the following illustration.

Copyright © 2020 Leila Gharani 35 | P a g e


Power Query Solutions to Appending Data Challenges

If we open the Data Model, we now have three separate tables (separate sheets) displayed.

We can view a graphical representation of the table relationships by selecting the Diagram View.

Creating the Pivot Table Reports


Sales by Customer Report

6. Select the cell to place the Pivot Table and click Insert (tab) → Tables (group) → Pivot Table.

7. In the Create PivotTable dialog box, select Use this workbook’s Data Model and click OK.

We can see the three tables listed in the PivotTable Fields list.

36 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

8. Place the MasterCustomer → Customer Name field in the Rows drop zone.

9. Place the TableSales → Sales Value field in the Values drop zone.

10. Sort the table results by Sales Value in descending order.

11. Format the Pivot Table with a Tabular style.

12. Format the Sales Values with a comma style, no decimal places.

Quantity by Article Description

13. Select the cell to place the Pivot Table and click Insert (tab) → Tables (group) → Pivot Table.

Copyright © 2020 Leila Gharani 37 | P a g e


Power Query Solutions to Appending Data Challenges

14. In the Create PivotTable dialog box, select Use this workbook’s Data Model and click OK.

15. Place the MasterArticle → Article Description field in the Rows drop zone.

16. Place the TableSales → Quantity field in the Values drop zone.

17. Sort the table results by Quantity in descending order.

18. Format the Pivot Table with a Tabular style.

19. Format the Sales Values with a comma style, no decimal places.

NOTE: In the PivotTable Fields list, you can hide fields you don’t wish to see (either to make the list less
visually cluttered or to hide fields from the user), by switching to the Data Model → Diagram View and
right-clicking on a field. This will allow you to use the “Hide from Client Tools” option on the selected
field.

38 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

Power Pivot Tip


Pivot Tables that are created from Power Pivot Data Models can display the Grand Total even when
filtering the table results.

To use this feature, open the PivotTable Options dialog box and select Tools & Filters (tab) → Filters
(group) → Include filtered items in totals. Also, consider displaying an asterisk for the total to indicate a
non-filtered sum.

Copyright © 2020 Leila Gharani 39 | P a g e


Power Query Solutions to Appending Data Challenges

COMBINE DATA FROM MULTIPLE WORKBOOKS


Appending Data
NOTE: Unless you need to use any of the original queries’ results, you will be better served to save the
source queries as Connection Only queries. The final query of appended results will be stored as a table
in Excel.

Creating the Appended Query


To create an appended query in Excel (this produces a new query):
1. Select Data (tab) → Get & Transform (group) → Get Data → Combine Queries → Append.
To create an appended query in Power Query:
1. Select Home (tab) → Combine (group) → Append Queries/Append Queries as New.
2. In the Append dialog box, select the two query results you wish to append to one another and
click OK.

40 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

If you need to append more than two query results, select “Three or more tables” and place the desired
queries in the “Tables to append” list (right).

Copyright © 2020 Leila Gharani 41 | P a g e


Power Query Solutions to Appending Data Challenges

COMBINE ALL EXCEL FILES IN A FOLDER


When you have many files that have the same structure, combining (appending) from a folder will allow
you to have as many files as you need while creating a single query to append them together.
When you add new files to the folder, a simple Refresh operation will integrate the new file’s data into
the original results list.
To begin the process of importing files from a folder:
1. Select Data (tab) → Get & Transform → Get Data → From File → From Folder.
2. In the Folder dialog box, browse to the folder’s location and select the desired folder and click
OK.

3. This displays a list of all files in the selected folder.

42 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

4. If you know the files are perfectly identical and require no further transformations, select
Combine. Otherwise, select Transform Data.

5. If you select Transform Data, you are placed in the Power Query Editor where all file metadata is
displayed.

6. From here, you can perform such operations as:


• Standardize casing for names and/or extensions
• Sort & filter by filename
• Sort & filter by file extension
• Sort & filter by date
7. Once the list has been reduced (if necessary) to display only the needed files, the files’ contents
can be extracted and combined using the Combine Binaries feature (upper-right of Content
column).

Copyright © 2020 Leila Gharani 43 | P a g e


Power Query Solutions to Appending Data Challenges

8. In the Combine Files dialog box, we are presented with the options(s) as to which sheets or
tables we want from each file in the folder.

9. Select the requisite table or sheet and click OK.


The result is appended data from all selected files in the folder.
Examining the Combine Files Transformation Steps
When combining files from a folder, Power Query must perform several transformations to arrive at the
desired result.
These transformations can be seen in the Queries & Connections panel.

44 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

The final results are stored in a query named “Append from Folder” located in the “Other Queries”
group.
The prerequisite transformations are stored in the “Helper Queries” group.
If you need to transform the files before the append operation, the alterations to the query need to be
performed in the Helper Queries – Transform Sample File query.
Typically, the transformations can occur before or after the append operation and the results will be
identical. Performance increases can be achieved when performing certain tasks before the append
step.
A Very Helpful Step in the Query
During the final query for the append operation, there is a step that filters out hidden files.

This is an automatic behavior that prevents open Excel files from being incorporated into the append
operation. This would otherwise result in the same data being loaded twice into the output.

NOTE: If you are running an older version of Power Query that does not possess this feature, it will be
necessary to manually add a step that filters out files whose names begin with a “~” (tilde) character.

Future-Proofing Your Query


Even if your query is initially examining perfect data, you may wish to add steps to address issues that
may come up in future refresh operations. These include, but are not limited to:

• Standardize the casing of names and/or extensions (i.e. standardize .CSV, .csv, .Csv, etc.)
• Only include files that equal a certain extension (ex: .xlsx)
• Only include files with a modification date before or after a certain day.
• Remove null rows
Copyright © 2020 Leila Gharani 45 | P a g e
Power Query Solutions to Appending Data Challenges

ADJUST FOLDER PATH FROM LOCAL TO SHAREPOINT DRIVE


If you create a query that pulls data from a local folder, but later decide to use a folder located on a
SharePoint drive, the Source steps in the queries will need to be redirected.
One way to adjust existing local folder pointers to SharePoint folder pointers is to perform the following
steps:
1. Navigate to the SharePoint folder that contains the needed files.
2. Locate the SharePoint URL in the browser’s address bar. The URL contains more information
than needed. Highlight starting from the left side of the address up to the word “Team”.

3. Create a new query by selecting Data (tab) → Get & Transform (group) → Get Data → From File
→ From SharePoint Folder.
4. Paste the URL copied from Step 2 into the Site URL field of the SharePoint Folder dialog box.

NOTE: If this is your initial connection to SharePoint, you will be required to supply your credentials to
gain access to the site and its content.

5. In the list of files from the SharePoint drive, click Transform Data.
6. Scroll to the column labeled “Folder Path” and filter for the desired subfolder.

NOTE: If you provide more of the path in the filter argument, the more focused (i.e. restrictive) the file
retrieval will be.

7. Rename the new query something like “SharePointDrive”. Remember this name; it will be
referenced towards the end of this solution.

8. Return to the original query that contains the file combining and transformation and select the
Source step.

46 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

9. Replace the entry in the Formula Bar with the name of the previously created query (Step 7).

10. Perform the same operation on the “Sample File” query as was performed on Step 9.

11. We do not want to load the results of the “SharePointDrive” query to an Excel table, so we will
perform a Close & Load operation as a “Connection Only” query.

Copyright © 2020 Leila Gharani 47 | P a g e


Power Query Solutions to Appending Data Challenges

COMBINE ALL SHEETS IN A FILE


When you have many sheets with data that have the same structure, combining (appending) from all
sheets in a file will save much manual labor of copying and pasting data into a single table.
As a condition of this example, we want the final report in a separate file from the source data.
1. Start a new workbook and select Data (tab) → Get & Transform (group) → Get Data → From
File → From File.
2. Browse to and select the required workbook and click Import.
3. In the Navigator dialog box, select the filename listed at the top of the sheet hierarchy list.

NOTE: If you select multiple sheets using the “Select multiple items” and the checkboxes, Power Query
will create a separate query for each selected sheet.

4. Select Transform Data.


5. Power Query will display the contents of the file. Each table will be stored as a nested table in
the Data column.

48 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

NOTE: Consider filtering out sheets/tables you do not require in your analysis.

6. Remove all columns except the Name and Data columns.


7. Click the Expand Columns button (upper-right of Data column) and expand all fields (deselect
the “Use original column names as prefix” option).

The remaining steps will be standard transformations, such as:


1. Row removal
2. Heading promotion
3. Column heading renaming
4. Data typing
5. Filtering
Overcoming Potential Errors when Combining Sheets
In the previous example, we saw how to combine tables from multiple sheets in the same file.
The example has a weakness; we have a step that promotes the first row as a header row. The issue is
that the Name column is replaced with the name of the first sheet in the workbook.

Copyright © 2020 Leila Gharani 49 | P a g e


Power Query Solutions to Appending Data Challenges

This works well until the first sheet in the workbook changes.

50 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

This will cause a following step to fail. When we rename the first column to “Company”, Power Query is
looking for a column named “Bere Kleid Data”. Since the new first sheet is named “Urban Right Data”,
the rename step fails.

Solution #1 Reordering Query Steps


The solution to this is to perform the row filtering before the header row promotion and column
rename.
This will increase the work for the column rename step because all columns will need to be renamed,
not just the first column. This is a small price to pay for a more robust, “future-proof” query.
Solution #2 “M” Code Modification
We have already identified that when a new “first sheet” is added to the file, an error occurs at the
Rename Columns step in the query.

Instead of looking for the column by its name, we can look for a column by its column position.
We will modify the reference to “Bere Kleid Data” with the following “M” code.

List.First(Table.ColumnNames(#”Promoted Headers”))

Copyright © 2020 Leila Gharani 51 | P a g e


Power Query Solutions to Appending Data Challenges

CONSOLIDATE DATA FROM MULTIPLE SHEETS IN THE CURRENT WORKBOOK


To incorporate new sheets as they are added to the file, we can capitalize on the table names.
Structure
For our example, we have six sheets (Jan thru Jun) that are formatted as proper Excel Tables.
The tables are named “Data_Jan” thru “Data_Jun”

The tables all have the same columns (number and headings).
Issues / Considerations
We have an issue where some columns have empty cells on certain rows. The implication is that if we
are selling different items to the same Customer or on the same Sales Document, the repetitive
information will not be repeated.

This is something that will need to be taken care of when processing the query.
Creating a Query from the Ground Up
Because we don’t want to create a separate query for each sheet/table, and we don’t want to be
burdened with updates every month, we will solve this with a bit of M code.
1. Select Data (tab) → Get & Transform (group) → Get Data → From Other Sources → Blank
Query.
2. In the Formula Bar, type the following (watch your capitalization):

= Excel.CurrentWorkbook()
52 | P a g e Copyright © 2020 Leila Gharani
Power Query Solutions to Appending Data Challenges

We are presented with a table that lists all detected tables and their respective names.

3. Rename the query “AllData”.


Because Document Date information is part of the table data, we do not need to keep the Name column
in the preview table.
4. Remove the Date column.
5. Expand the Content column to include all columns (deselect the “Use original column name as
prefix” option).
We are delivered all the data appended to one another in a single table.

NOTE: Because we are working with Excel Tables, we do not retain the heading rows from the
subsequent tables. Duplicate headings are removed automatically.

6. Filter the rows containing the words “Grand Total” from the Sales Document column.
7. Replace the nulls by selecting the Sales Document and Customer Name columns. Select
Transform (tab) → Any Column (group) → Fill → Fill Down.
8. Select all columns and assign proper data types; Transform (tab) → Any Column (group) →
Detect Data Type. Adjust as necessary (ex: Document Date to Date.)

Copyright © 2020 Leila Gharani 53 | P a g e


Power Query Solutions to Appending Data Challenges

A Subversive Little Problem


Once we send the data to an Excel Table, we see that there are 283 rows in the query output.

Without changing ANYTHING, we refresh the query and observe what happens to our row count.

Each time we refresh, the row count increases to an unexpected value.


The problem is that the output query is storing its results in the same file as the source material and it is
storing it as a proper Excel Table.

This means that each time the query refreshes, it will read EVERY table in the workbook, including the
output table. We refer to this as “the snake eating its tail.”
We can see from the Source step in the query that the query output table is seen as a viable input table.

54 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

To exclude the output sheet from the Refresh operation, we can insert a step in the query after the
Source step that filters the table to only include tables whose table names begin with “Data_”.Better
Collaboration – File Path as Parameter
When creating queries, it is not uncommon for our Source step to point to a local drive/folder/filename
for the data.
The problem occurs when the file(s) is sent to another user who does not maintain the same
drive/folder/file environment. We will be in constant need of updating the Source step in the query.
We can eliminate the need for Source updates by using a parameter.
Parameters can be implemented as:

• Power Query Parameters

• Excel Parameters

Copyright © 2020 Leila Gharani 55 | P a g e


Power Query Solutions to Appending Data Challenges

HOW TO SELECT FILE PATH WITH POWER QUERY PARAMETERS


If you create solutions that you’re planning to share with others and these solutions import external
files, you can use Power Query parameters for the file path to make it easier to change the source based
on the file location on each person’s workstation. (If possible, it’s always best to use a SharePoint drive).
To create and manage parameter in Power Query, perform the following steps:

1. In Power Query, select Home (tab) → Parameters (group) → Manage Parameters → New
Parameter.

2. In the Manage Parameters dialog box, enter the following information:

• Name (ex: PathParameter)

• Description

• Type (ex: Text)

• Suggested Values

• Current Value

56 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

This produces a Parameter.

Pointing a Query to Use a Power Query Parameter

1. Select a query and click the Source step.

2. Replace the hard-coded portion of the patch (ex: C:\PQ\21) with the name of the parameter
followed by a concatenate symbol (&).

= Excel.Workbook(File.Contents(PathParameter & “\DataSales.xlsx”), null, true)

Copyright © 2020 Leila Gharani 57 | P a g e


Power Query Solutions to Appending Data Challenges

MANAGE THE FILE PATH FROM AN EXCEL CELL


To create and manage parameters in Excel, perform the following steps:

1. Create an Excel Table (or Named Range) with the heading FilePath and a single row that contains
the file’s full path. (you can use other heading names)

2. Name the table “FileExcelPath”. (you can use other table names)

3. Select a cell in the table and click Data (tab) → Get & Transform (group) → From Table/Range.

4. Remove the Changed Type step.

5. Right-click on the path in the table and select Drill Down.

6. Close & Load as a Connection Only query.

Pointing a Query to Use an Excel Parameter

1. Select a query and click the Source step.

2. Replace the hard-coded portion of the patch (ex: C:\PQ\21) with the name of the parameter
followed by a concatenate symbol (&).

= Excel.Workbook(File.Contents(FileExcelPath & “\DataSales.xlsx”), null, true)

58 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

Unfortunately, we are presented with the following error:

Power Query does not like the fact that two connections have been made within a single query; in other
words, the Path (99% of it, anyway) is coming from one query while the filename is coming from another
query.
There are two ways to deal with this issue:

1. Ignore the error

a. Select File (tab) → Options & Settings → Query Options.

b. In the Current Workbook → Privacy section and select the “Ignore the Privacy Levels and
potentially improve performance” option.

2. Resolve the path determination in the same query as the filename pointer.

a. Combine the steps in the FileExcelPath query by updating the Source step as follows:

= Excel.CurrentWorkbook(){[Name="FileExcelPath"]}[Content]{0}[File Path]

3. Remove all other steps in the FileExcelPath query.

4. Highlight and copy the entire Source step from the FileExcelPath query.

5. Edit each remaining query.

a. Insert a step before the Source step by selecting Home (tab) → Query (group) →
Advanced Editor and add a blank row below the “let” statement (row 2).

b. Paste the copied data from Step 4 into the newly inserted blank row.

c. Add the label “FileExcelPath” before the equals sign of the new row.

d. Add a comma to the end of the new row.

FileExcelPath = Excel.CurrentWorkbook(){[Name="FileExcelPath"]}[Content]{0}[File Path],

Copyright © 2020 Leila Gharani 59 | P a g e


Power Query Solutions to Appending Data Challenges

Generating File Paths Automatically

NOTE: The below tip assumes that the report file and the source files are stored in the same folder.

You can use the Excel CELL function to generate the path/filename/sheetname of the current workbook.

=CELL(“filename”)

This will generate a result such as the following:

C:\PQ\S21\[Report.xlsx]Index

We need to extract everything to the left of the final backslash, the one just before the open square
bracket. Assuming the CELL function in cell A1, we can use additional functions to extract the needed
path.

=LEFT(A1, SEARCH("[", A1) - 2)

If you wish to obtain this information in a single formula, we can combine the two formulas into one like
the following:

=LEFT(CELL("filename"), SEARCH("[", CELL("filename")) - 2)

60 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

IMPORT FROM FOLDER & CLEAN HEADERS


It has been discussed that one of the requirements for appending data from multiple files is that the
headers need to match in terms of naming and casing.
Suppose you have files that have the same headings, but the casing has not been standardized from file
to file. One file may have a heading labeled “QUANTITY”, while another file uses the label “Quantity” or
perhaps “quantity”.
To solve this issue:

1. Open a blank workbook and select Data (tab) → Get & Transform (group) → Get Data → From
File → From Folder.

2. Browse to the desired folder location.

3. Filter the Name column, if necessary (ex: all files that contain “_Data”).

4. Filter the Extension column for specific file type (if necessary (ex: .xlsx files)

5. Rename query to “AllData”.

6. Click Combine Binaries button

7. From the Combine Binaries dialog box, select the Data tab and click OK.

8. In the Queries panel (left), select the Transform Sample File query.

9. Delete the Promote Headers step from the Queries step list.

10. Remove the top 2 rows.

11. Promote the first row as headers

12. Remove the automatically applied Changed Type step.

At this point, if the columns headings in the source files do not match in casing, nulls will result in
various locations throughout the table. To standardize the casing, we will create a custom step in the
query.

13. Select the last step in the query and click the button to the left of the Formula Bar.

14. In the Formula Bar, enter the following formula:

= Table.TransformColumnNames( #”Promoted Headers”, each Text.Proper( _ ) )


Copyright © 2020 Leila Gharani 61 | P a g e
Power Query Solutions to Appending Data Challenges

NOTE: The underscore used in the Text.Proper function is a technique for referring to the entire column
as opposed to a specific column like [Company].

The headings may likely have leading and/or trailing spaces. These need to be stripped out.

15. Modify the formula from Step 14 to include the Text.Trim function before the Text.Proper
function.

= Table.TransformColumnNames( #”Promoted Headers”, each Text.Trim(Text.Proper( _ ) ) )

16. Rename the newly created step to “UpdatedHeaders”.

17. Using the “Sales Document” column, filter out the null entries.

If you return to the final query output named “AllData”, we see that all of the data has been appended
properly based on consistent headings.

62 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

HOW TO APPEND ALL SHEETS WHEN DATA STARTS FROM DIFFERENT ROWS
It’s not uncommon for tables to start on different rows between different files.
Objectives

• Combine (append) data from separate files into a table in a new Excel file.

• Use a column heading to act as an identifier for the start of the table(s).

In this example, we will use the column heading labeled “Sales Document” as our heading row
identifier.

1. Open a blank workbook and select Data (tab) → Get & Transform (group) → Get Data → From
File → From Workbook.

2. Browse to the desired file.

3. In the Navigator dialog box, select the parent “folder” that appears above the list of sheet
names.

4. Click Transform Data.

5. Rename the query “AllData”.

We need to determine the row number of each sheet where the term “Sales Document” appears in
“Column 1”

6. Select Add Column (tab) → General (grop) → Custom Column.

7. In the Add Column dialog box, enter the following formula:

= List.PositionOf([Data][Column1], “Sales Document”)

We are presented with a row result for each table where the text “Sales Document” is first encountered.

NOTE: Don’t forget that Power Query starts counting at 0 (zero). Therefore, 0 would be “row 1”.

Copyright © 2020 Leila Gharani 63 | P a g e


Power Query Solutions to Appending Data Challenges

8. To use the discovered row number information, click the gear icon next to the newly inserted
step and adjust the formula as follows:

= Table.RemoveFirstN([Data], List.PositionOf([Data][Column1], “Sales Document”) )

Each table will now begin its data starting on the first row.
We can improve this by promoting the first row in each table to a header row.

9. Click the gear icon next to the newly updated step and adjust the formula as follows>

= Table.PromoteHeaders(Table.RemoveFirstN([Data], List.PositionOf([Data][Column1], “Sales


Document”) ) )

10. Select the Name column and the last column (our custom results) and remove the other
columns.

11. Expand the nested tables in the custom column.

12. Filter the null values from the “Sales Document” column.

13. Select all columns and detect the data types.

14. Close & Load the results to an Excel Table.

64 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

APPEND SHEETS AND GET FIELD NAME FROM A CELL OUTSIDE THE TABLE
Objectives:

• Create tables that include a column for the company’s name.

• Append the tables into a single output table in a separate file.

• Accommodate the addition of new sheets in the source workbook.

Issues:

• The company’s name is located in a cell directly above the table’s header row in Column B to the
right of the word “Company”.

• The tables do not all start on row 1 in the worksheets.

• The tables are not formatted as proper Excel Tables.

Solution Steps:

1. Open a blank workbook and select Data (tab) → Get & Transform (group) → Get Data → From
File → From Workbook.

2. Browse to the desired file.

3. In the Navigator dialog box, select the parent “folder” that appears above the list of sheet
names.

4. Click Transform Data.

5. Rename the query “AllData”.

Create a Custom Column that locates the row number holding the word “Company”.

6. Select Add Column (tab) → General (group) → Custom Column.

7. In the Custom Column dialog box, add the following formula:

= List.PositionOf([Data][Column1], “Company”)

8. To use the discovered row number information, click the gear icon next to the newly inserted
step and adjust the formula as follows:

= Table.RemoveFirstN([Data], List.PositionOf([Data][Column1], “Company”) )


Copyright © 2020 Leila Gharani 65 | P a g e
Power Query Solutions to Appending Data Challenges

9. Select the Custom column and remove all other columns.

10. Expand the contents of the Custom column.

Determine the company name and place it in a separate column by way of a Conditional Column.

11. Select Add Column (tab) → General (group) → Conditional Column.

12. Add the following parameters to the Add Conditional Column dialog box.

13. Select the newly inserted custom column and fill the contents down the column (Fill Down).

14. Filter Column1 to remove nulls and “Company”.

15. Promote the first row to a header.

16. Remove the automatically applied “Changed Type” step.

17. Remove the redundant, embedded header rows from the data by filtering the “Sales Document”
column and deselect “Sales Document”.

18. Change the last column (company names) header to “Company”.

Because the original header label for the company column is hardcoded to the name of the first sheet’s
company in the workbook, we need to include logic to detect the name of the first sheet’s company so
this will be dynamic and “future-proof”.
We can solve this problem with either “M” code or re-work our steps from the interface controls.

66 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

The “M” Code Solution

19. Select the “Filtered Rows1” step and insert a new step below this position.

20. Update the Formula Bar to the following:

= List.Last(Table.ColumnNames(#”Filtered Rows1”) )

21. Highlight the above formula in the Formula Bar and copy it to memory.

22. Delete the above custom step.

23. Select the “Renamed Columns” step and modify the instruction in the Formula Bar as follows
(replace the static reference to “Bere Kleid” with the copied formula):

=Table.RenameColumns(#”Filtered Rows1”, { {List.Last(Table.ColumnNames(#”Filtered Rows1”) ),


“Company”} } )

24. Apply proper data types.

The Interface Controls Solution

19. Remove all steps after the “Filtered Rows” step.

20. Update the “Filtered Rows” step to include an additional filter parameter.

21. Manually rename each header with a proper heading name.

22. Apply proper data types


Copyright © 2020 Leila Gharani 67 | P a g e
Power Query Solutions to Appending Data Challenges

UNPIVOT & CONSOLIDATE DATA FROM MULTIPLE SHEETS


Report Requirements:

• Create a separate table that consolidates all of the below-listed data.

• Create a separate table in a separate Excel workbook.

• Accommodate the addition of new company sheets.

• Accommodate the addition of new months in the data columns.

• Eliminate the totals in the final output table.

• Ensure Company Name appears on each row.

• Single column to hold month names.

• Single column to hold sales values.

• Additional columns to store the company name for each row.

Data Design:

• The sales information is stored in tables where each table is dedicated to a separate company.

• Each table is on a separate sheet.

• The tables have the same column structure.

• The table is set up in a cross-tabular structure; Customer Name and Article Description for rows
and Months for columns.

• The Company Name is located above the table in cell B1 and within the sheet name.

• The sheets that contain needed data have their sheet names begin with “Data_”.

Solution Steps:

1. Open a blank workbook and select Data (tab) → Get & Transform (group) → Get Data → From
File → From Workbook.

2. Browse to the desired file.

68 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

3. In the Navigator dialog box, select the parent “folder” that appears above the list of sheet
names.

4. Click Transform Data.

5. Rename the query “AllData”.

6. Filter the Name column to only include items that begin with “Data_”.

Create a function that will process the nested tables (Data column) before the append operation.

7. Duplicate the query.

8. Rename the second query to “TransformSample”.

9. Extract the first table by clicking the Table hyperlink in the Data column.

10. Remove the automatically applied “Changed Type” and “Promoted Headers” steps.

11. Remove the top 2 rows.

12. Promote the first row as headers.

13. Remove the automatically applied “Changed Type” step.

14. Remove the nulls by filling down the Customer Name column.

15. Filter out the total rows (Does not end with… “Total”).

16. Unpivot the table by selecting the Customer Name and Article Description columns and unpivot
the other columns.

Convert the Attribute column to usable dates.

17. Add the suffix “,2020” to the Attribute column.

18. Rename the Attribute column to Date.

19. Rename the Value column to Sales Value.

Convert the previous table manipulation steps into a reusable function.

20. Open the TransformSample function in the Advanced Editor.

21. Comment out the first three transformations.

Copyright © 2020 Leila Gharani 69 | P a g e


Power Query Solutions to Appending Data Challenges

22. Add the following instruction above the let statement at the top of the query:

(mytable as table ) =>

23. Replace the reference to #"Data_Urban Right_Sheet" with mytable.

Use the function to process the nested tables in the original query.

24. Invoke a Custom Function with the following arguments:

25. Select the Name and TransformSample columns and remove all other columns.

26. Expand the TransformSample column.

70 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Appending Data Challenges

Extract the company name from the Name column.

27. Select the Name column and Extract → Text After Delimiter using “Data_” as the delimiter.

28. Rename the Name column to Company.

29. Select all columns and detect data types.

30. Close & Load the results to a table in the new workbook.

Copyright © 2020 Leila Gharani 71 | P a g e


Solutions to
Common Data
Analysis
Problems
Power Query Solutions to Common Data Analysis Problems

HOW TO CREATE BUCKETS FOR YOUR DATA


We are presented with the dataset below.

Our objective is:

• Please group the employees under the following criteria.


o LOW = anyone earning below 30K
o AVERAGE = anyone earning between 30K and 50K
o MODERATE = anyone earning between 50K and 90K
o HIGH = anyone earning over 90K
• The results should appear as a new column in the results table.
Step 1: Load the Data into Power Query as an Excel Table
1. Click in the original data and select Data (tab) → Get & Transform (group) → From,
Table/Range.

2. In the Create Table dialog box, verify the proper range selection and ensure the “My table has
headers” option is selected.

Copyright © 2020 Leila Gharani 73 | P a g e


Power Query Solutions to Common Data Analysis Problems

Step 2: Create the New Column Using the Column From Example Feature

3. Select the Salary column.,

4. Select Add Column (tab) → General (group) → Column From Example → From Selection.

Step 3: Define a Pattern for the Categorization of Salaries

5. In the test column (Custom), provide some examples of where particular salaries would fall in
your naming scheme. You may need to define 1 or 2 examples in each bucket range for Power
Query to figure out your ranges.

In the logic area, we can see sample logic that Power Query is attempting to apply based on our
suggestions.

If we apply the suggestions, we can see the final formula is as follows:

= Table.AddColumn(#"Changed Type", "Custom", each if [Salary] >= 145000 then "High" else if
[Salary] >= 58300 then "Moderate" else if [Salary] >= 31200 then "Average" else "Low", type text)

The logic is good, but the thresholds for each bucket is incorrect.
Step 4: Refining the Logic of Columns From Example

74 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

NOTE: We could make the following changes directly in the Formula Bar, but you may feel more
comfortable using a user-friendly dialog box to relieve yourself of any risk of typographic, logic, or syntax
errors.

6. To adjust the thresholds of each bucket from Step 5, click the gear icon to open the Added
Conditional Column step.

7. In the Add Conditional Column dialog box, adjust the Values fields to reflect the desired bucket
ranges.

8. Click OK to commit the changes.

At this point, we can Close & Load this to a new table, a Pivot Table/Chart, or into our Data Model

Copyright © 2020 Leila Gharani 75 | P a g e


Power Query Solutions to Common Data Analysis Problems

CHANGING SOURCE FILE LOCATION FROM LOCAL TO SHAREPOINT


1. Open a browser and access your SharePoint drive or OneDrive for Business drive.
2. Upload the local file to SharePoint.
3. Locate the file by which you require a connection.
4. Click the “three stacked dots” to the right of the file’s name.

5. In the menu, select Details.


6. In the details panel (right), scroll to the bottom, and locate the Path.

7. Click the icon to the right of Path to copy the link address to memory.

76 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

8. To access the SharePoint file, select Data (tab) → Get & Transform (tab) → Get Data → From
Web and paste the copied link into the URL field and click OK.

NOTE: Because the source pointer is not pointing to your local computer, if you share this file and a user
attempts a refresh of the data, they will be required to enter their SharePoint or OneDrive for Business
credentials

9. In the Navigator dialog box, select the requisite table from the list of sources (left).

10. Name the new query something like “SalesSharePoint”. Remember this name; it will be
referenced towards the end of this solution.

11. Remove all of the steps except for the Source step.

12. We’re not going to perform any of the original transformations, so select Load → Load to…

13. Select Only Create Connection.

14. Click OK.

This creates a “placeholder” query where we can extract the needed pointer for the new file location.

15. Open the original query that pointed to the local file.

16. Select the Source step.

17. Erase everything in the Formula Bar that pointed to the original file location/name/range.

18. In the Formula Bar, type the following formula (a reference to another query):

= SalesSharePoint

Copyright © 2020 Leila Gharani 77 | P a g e


Power Query Solutions to Common Data Analysis Problems

MESSY DATA FROM MULTIPLE ROWS TO ONE ROW – CREATING A PROPER


DATA SET
Issues / Requirements:

• Customer IDs are repeated.

• There are gaps in the data.

• Phone numbers are not always on the same row as the first Customer ID instance.

• Customer names are not always on the same row as the first Customer ID instance.

• Create a table with one row per Customer ID with the associated information.

Solution Steps:
Convert and Load the Data

1. Select cells A4 through C17 and convert the table to a proper Excel Table (CTRL-T).

2. Name the Excel Table “MessyData”.

3. Load the Excel Table into Power Query.

Create Separate Phone and Customer Name Tables

4. Duplicate the MessyData query.

5. Rename the queries “GetName” and “GetPhone”.

6. Select the GetName query.

7. Remove the Phone column.

8. Filter the nulls from the Customer Name column.

9. For “future-proofing” purposes, select both columns and Remove Duplicates.

10. Select the GetPhone query.

11. Remove the Customer Name column.

12. Filter the nulls from the Phone column.

13. For “future-proofing” purposes, select both columns and Remove Duplicates.
78 | P a g e Copyright © 2020 Leila Gharani
Power Query Solutions to Common Data Analysis Problems

Merge the Table Results

14. Select Home (tab) → Combine (group) → Merge Queries → Merge Queries as New.

15. In the Merge dialog box, set the parameters shown in the following illustration.

16. Expand the nested tables in the Phone column to extract the Phone field.

17. Name the merge results query “CleanData”.

18. Close & Load the results to an Excel Table.

The results are as follows:

Copyright © 2020 Leila Gharani 79 | P a g e


Power Query Solutions to Common Data Analysis Problems

SEARCH AND REPLACE BULK VALUES


Issues / Requirements:

• Import from a file that contains profit data by App.

• Create a Pivot Table by App and Profit.

• Ensure the App names are the updated App names (from the “After” column).

Solution Steps:
Load Data from File

1. Select Data (tab) → Get & Transform (group) → Get Data → From File → From Workbook.

2. Browse to and load the “Source_App_Data.xlsx” file.

3. Select the Data tab and click Transform Data.

4. Filter to remove any zero values from the Profit column.

5. Close & Load to create a Connection Only load.

6. Select the table of Before/After names (B4 through C10) and convert the table to a proper Excel
Table (CTRL-T).

7. Name the Excel Table “TransformTable”.

8. Load the Excel Table into Power Query.

9. Close & Load to create a Connection Only load.

Merge the Tables to Produce the Finished Table

10. Select Data (tab) → Get & Transform (group) → Get Data → Combine Queries → Merge.

80 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

11. In the Merge dialog box, set the parameters shown in the following illustration.

12. Expand the nested tables in the TransformTable column to extract the After field.

Correcting for Apps Without New Names

13. Create a Conditional Column with the following parameters.

Copyright © 2020 Leila Gharani 81 | P a g e


Power Query Solutions to Common Data Analysis Problems

14. Set the data type for the New App Name column to Text.

15. Remove the original App and App columns.

16. Rename the New App Name column to App.

17. Name the merge results query “UpdatedData”.

18. Close & Load the results to an Excel Table.

The results are as follows:

82 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

CALCULATE VALUE DIFFERENCE TO PREVIOUS ROW – MERGE A QUERY WITH


ITSELF
Issues / Requirements:

• Import from a text file that contains Gold prices by date.

• Create a new column in Power Query that calculates the difference between the current day
price and the previous day price.

Solution Steps:
Load Data from Text File

1. Select Data (tab) → Get & Transform (group) → Get Data → From File → From Text/CSV.

2. Browse to and load the “Gold_Prices.txt” file.

3. Click Transform Data.

NOTE: If the Dates and Prices come in as errors, it’s likely due to a regional settings issue. Consider
adding steps to use Locale → Date → English (United States) and Locale → Decimal Number→ English
(United States) respectively.

Merge the Table with Itself to Create the Difference Column

4. Add an Index column by selecting Add Column (tab) → General (group) → Index Column
(starting at 0).

5. Add a second Index column by selecting Add Column (tab) → General (group) → Index Column
(starting at 1).

6. Select Home (tab) → Combine (group) → Merge Queries.

Copyright © 2020 Leila Gharani 83 | P a g e


Power Query Solutions to Common Data Analysis Problems

7. In the Merge dialog box, set the parameters shown in the following illustration.

8. Expand the column of nested tables to include the Gold Price Close column.

9. The table has lost its original sort order, so restore the sort order by sorting the Index column in
Ascending order.

10. Create the Difference column by selecting the Gold Price Close and the Gold Price Close.1
columns and clicking Add Column (tab) → From Number (group) → Standard → Subtract.

11. Remove the index columns.

12. Rename the Subtraction column to Difference.

13. Close & Load the results to an Excel Table.

The results are as follows:

84 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

APPROXIMATE MATCH LOOKUP WITH MERGE


Issues / Requirements:

• We have an Excel Table named “TBonus” with bonus amounts based on salary thresholds.

• We have salary information in a separate file names Salary.xlsx.

• Create a new table that contains the employee names, their bonus rate, and the bonus amount.

• Only include employees that receive a bonus.

Solution Steps:
Load Data from Tables

1. Select a cell in the TBonus table and load the table into Power Query as a Table.

2. Close & Load as Connection Only.

3. Select Data (tab) → Get & Transform (group) → Get Data → From File → From Workbook.

4. Browse to and load the “Salary.xlsx” file.

5. Select the table named TSalary and click Load to… → Connection Only.

Merge Tables to Create Employee Bolus Calculations

7. Select Data (tab) → Get & Transform (group) → Get Data → Combine Queries → Merge.

8. In the Merge dialog box, set the parameters shown in the following illustration.

Copyright © 2020 Leila Gharani 85 | P a g e


Power Query Solutions to Common Data Analysis Problems

9. Expand the column of nested tables to include all fields.

10. Remove the Old Bonus column.

11. Create a Conditional Column named “Salary Help” that detects a null in the Salary.1 column and
repeats the value in the Salary column. If a salary exists in the Salary.1 column, repeat that same
value.

12. Set the data type for Salary Help to Whole Number.

13. Add an Index column by selecting Add Column (tab) → General (group) → Index Column
(starting at 0).

14. Sort the table by the Salary Help column in Ascending order.

15. Fill Down the Bonus column.

16. Sort the table by the Index column in Ascending order.

17. Filter out any Bonus rows that equal to zero (filter “does not equal 0”).

18. Remove the Salary.1, Salary Help, and Index columns.

19. Create the Bonus Amount column by selecting the Salary and the Bonus columns and clicking
Add Column (tab) → From Number (group) → Standard → Multiply.

20. Rename the Multiplication column to Bonus Amount.

21. Change the data type for the Bonus Amount column to Currency.

22. Close & Load the results to an Excel Table.

The results are as follows:

86 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

CREATE A REPORT BASED ON MULTIPLE EXCEL PARAMETERS


Issues / Requirements:

• We have an Excel Table named “TEmployee” that consists of names, salaries, departments, and
positions on a sheet named Source.

• We have an Excel Table named “TableThreshold” that consists of departments and thresholds on
a sheet named “Report”.

• Create a report of employees whose salary is above the threshold for their respective
departments.

• Sort the results in ascending order by the department and then descending order by the salary.

• The report needs to be fully dynamic to allow for additions to the Source as well as changes to
the thresholds.

Solution Steps:
Load Data from Tables

1. Select a cell in the TableThreshold table and load the table into Power Query as a Table.

2. Close & Load as Connection Only.

3. Select a cell in the TEmployee table and load the table into Power Query as a Table.

4. Close & Load as Connection Only.

Merge the Tables to Produce the Results

5. Select Home (tab) → Combine (group) → Merge Queries.

Copyright © 2020 Leila Gharani 87 | P a g e


Power Query Solutions to Common Data Analysis Problems

6. In the Merge dialog box, set the parameters shown in the following illustration.

7. Expand the nested tables in the TableThreshold column to extract all fields

8. Filter out any rows containing nulls from the TableThreshold.Threshold column.

9. Create a Conditional Column named “Include” with the parameters shown in the following
illustration that flags any Salary entries that are Greater than or Equal to the
TableThreshold.Threshold column with a “YES”. Otherwise, display a null.

88 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

10. Filter the Include column to only retain rows with the “YES” flag.

11. Remove the TableThreshold.Dept, TableThreshold.Threshold, and Include columns.

12. Sort the results in Ascending order by Department and then Descending order by Salary.

13. Close & Load the results to an Excel Table.

The results are as follows:

Copyright © 2020 Leila Gharani 89 | P a g e


Power Query Solutions to Common Data Analysis Problems

FIND MISMATCHES IN DATA


Issues / Requirements:

• We suspect that someone has made alterations to the company salary spreadsheet.

• We also suspect that rows may have been deleted from the spreadsheet.

• We have a backup copy of the salary spreadsheet that was made before the suspected
alterations.

• Import the current file (SalaryCurrent.xlsx) and the backup file (SalaryBackup.xlsx) into Power
Query.

• Determine which were deleted (if any) and which salaries were altered (if any).

Solution Steps:
Importing the data files

1. Open a blank workbook and select Data (tab) → Get & Transform (group) → Get Data → From
File → From Workbook.

2. Import the SalaryCurrent.xlsx file

3. Rename the query “SalaryCurrent”.

4. Remove the automatically applied b and Promoted Headers steps.

5. Remove the top 3 rows by selecting Home (tab) → Reduce Rows (group) → Remove Rows →
Remove Top Rows.

6. Promote the first row as a header row.

7. Duplicate the SalaryCurrent query.

8. Rename the duplicate query to SalaryBackup.

9. Change the Source step to point to the SalaryBackup.xlsx file.

90 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

Comparing the File’s Contents

10. Select each query and note the number of listed rows (bottom left corner).

11. Close & Load both queries as Connection Only queries.

Perform a Merge to Determine the Differences

12. Perform a Merge operation on the two tables with the parameters shown in the following
illustration.

Copyright © 2020 Leila Gharani 91 | P a g e


Power Query Solutions to Common Data Analysis Problems

13. Rename the merged query Differences.

14. Expand the nested tables from the SalaryBackup column using the following selections:

• First Name
• Last Name
• Position
• Salary
• Use original column name as prefix

NOTE: The last option will help us keep track of which file the columns originated.

Compare the salaries by creating a Conditional Column.

15. Select Add Column (tab) → General (group) → Conditional Column.

16. Set the Conditional Column with the parameters shown in the following illustration.

17. Filter the Include column to only retain entries flagged “YES”.

18. Remove the Include column.

19. Close & Load the results to an Excel Table.

We now can easily see which rows were removed from the worksheet (yellow) and which salaries were
changed (purple).

92 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

NESTED RANK WITH POWER QUERY – RANK IN EACH GROUP


Issues / Requirements:

• We have an Excel Table named “TSales” which contains a list of dates, sales manager names,
product names, and sales values (over 2200 rows).

• We need to create a table that displays the Top 5 sales entries for each day.

Solution Steps:
Load the Date to a Query

1. Load the Excel Table into Power Query as a Table.

2. Rename the query to “Top5”.

3. Change the Date column to a Date data type.

4. Sort the table in Descending order by Sales.

5. Group the table by Date using the settings in the following illustration.

We will use a Custom Column function to create a list of index numbers (starting at 1) within each
nested table of the Custom column.

94 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

6. Insert a Custom Column and set the parameters shown in the following illustration.

=Table.AddIndexColumn([All], "Rank", 1)

7. Remove the All column.

8. Expand the column of nested tables to include all fields except Date.

9. Filter the table to only keep Ranks that are Less than or equal to 5.

10. Reorder the columns in Date – Rank – Sales Manager – Product Name – Sales order.

11. Apply the appropriate data types to all columns.

12. Sort the table in Ascending order by Date, then Ascending order by Rank.

13. Close & Load the results to an Excel Table.

The results are as follows:

Copyright © 2020 Leila Gharani 95 | P a g e


Power Query Solutions to Common Data Analysis Problems

ASSIGN UNIQUE NUMBERS TO A GROUP


Issues / Requirements:

• We have a list of customer names.

• The customer names are repeated in various quantities.

• Each customer name requires a unique ID starting from 10.

• Each time a new customer name is encountered, the unique ID is to be incremented by a value of
10 (ex: 10, 20, 30, 40, etc.)

Solution Steps:

1. Select a cell in the list of customer names and load the data into Power Query as a Range (no
header row).

2. Rename the query to “CustomerID”.

3. Change the data type for Column1 to Text.

4. In the Group By dialog box, set the parameters shown in the following illustration.

5. Add a custom index column by selecting Add Column (tab) → General (group) → Index Column
→ Custom…

96 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

6. In the Add Index Column dialog box, set the parameters to start at 10 and increment in intervals
of 10.

7. Expand the column of nested tables named Column1 to include all fields.

8. Rename the Column1.1 column to “Customer Name”.

9. Remove the index column.

10. Close & Load the results to an Excel Table.

The results are as follows:

Copyright © 2020 Leila Gharani 97 | P a g e


Power Query Solutions to Common Data Analysis Problems

UNPIVOT DATA WITH MULTIPLE HEADERS


Issues / Requirements:

• We have a list of customer’s names, article descriptions, and sales.

• Customer names are only listed for the first article description.

• Total rows occur after each customer's transactions.

• A Grand Total row occurs at the bottom of the data.

• The sales are aggregated at the monthly level displayed as month names.

• Each month has a scenario for Actual along with a value for Budget.

• The headings for the scenarios “Actual” and “Budget” are stored in merged cells that traverse all
three displayed months. This results in a double-row header.

• Display a table with the records categorized by the scenario.

• Exclude the total/grand total rows from the final report.

• The report needs to accommodate expansion when new months are added to the data.

Solution Steps: Prepare the Data as a Table

1. Select a cell in the data, press CTRL-A to select the entire data range.

2. Upgrade the table to a proper Excel Table by pressing CTRL-T and do not define headers in the
table.

3. Return the table to its original look by clearing the color formatting and turning off the Header
Row option.

4. Rename the table “TCustomer”.

5. Load the data into Power Query as a Table.

6. Perform a Fill Down operation on the customer names (Column1).

7. Merge the customer names (Column1) and the article descriptions (Column2) using a semicolon
as the delimiter into a new column named “Merged”.

8. Transpose the table by selecting Transform (tab) → Table (group) → Transpose.


98 | P a g e Copyright © 2020 Leila Gharani
Power Query Solutions to Common Data Analysis Problems

9. Perform a Fill Down operation on the scenario names (Column1).

10. Promote the first row as a header row.

11. Select the column of scenarios (;) and unpivot the other columns by clicking Transform (tab) →
Any Column (group) → Unpivot Columns → Unpivot Other Columns.

12. Select the Attribute column and split the column by delimiter. The delimiter is a semicolon that
is split at each occurrence.

13. Rename the columns.

Old Name New Name


; Scenario
CustomerName;ArticleDescription Date
Attribute.1 Customer
Attribute.2 Article
Value Sales Value

14. Filter the Customer column to keep rows that do not end with “Total”.

15. Change the data types for all columns.

16. Reorder the columns as Customer – Article – Scenario – Date – Sales Value.

17. Filter out the null values from the Sales Value column.

18. Close & Load the results to an Excel Table.

Copyright © 2020 Leila Gharani 99 | P a g e


Power Query Solutions to Common Data Analysis Problems

The results are as follows:

100 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

Summary of the steps to unpivot data with multiple row and column headers:
1. Identify anchor columns – these are the columns you want to keep
2. Fill down the anchor columns in case there are gaps
3. Merge anchor columns to create one column
4. Transpose the Table
5. Fill down the columns that have gaps
6. Promote first row to header
7. Select the new anchor columns and Unpivot Other Columns
8. Split the attribute column by delimiter
9. Continue with anything else that needs cleaning – for example filtering out total values

Copyright © 2020 Leila Gharani 101 | P a g e


Power Query Solutions to Common Data Analysis Problems

PIVOT DATA WITHOUT ANCHOR COLUMNS


Issues / Requirements:

• We have the following Excel Table named “MessyData2”:

• We are devoid of any “anchor” columns. Power Query has no way to identify which rows belong
to which record.

• We need to assign values where each related row receives the same number.

Solution Steps:

1. Load the Excel Table into Power Query as a Table.

2. Name the query “ProperAdvanced”.

3. Remove the automatically applied Changed Type step.

102 | P a g e Copyright © 2020 Leila Gharani


Power Query Solutions to Common Data Analysis Problems

Add a custom index column by selecting Add Column (tab) → General (group) → Index Column
(start with 0).

4. Flag the start of each group using a Conditional Column, setting the parameters as shown in the
following illustration.

5. Fill Down the newly added custom column named Custom.

6. Remove the Index column.

7. Select the Field Name column and click Transform (tab) → Any Column (group) → Pivot
Column. Set the Values Column to Value and the aggregation method to Don’t Aggregate.

8. Remove the Custom column (numeric associations).

9. Assign the proper data types to all columns.

10. Close & Load the results to an Excel Table.

The results are as follows:

Copyright © 2020 Leila Gharani 103 | P a g e


Power Query Solutions to Common Data Analysis Problems

Summary of the steps to pivot flat data to multiple columns:


1. Add an index column.
2. Think of a logic to separate each group of data the belongs to the same row:
a. If you have consistent number of columns, you can use a transformation on the index
column and use integer divide. The value will be the number of columns.
b. If you have an inconsistent number of columns, you can use a conditional column and
extract the index number based on the first column (this assumes the first column is
always present). Then Fill Down and remove the original index column.
3. Pivot the column that has the column headers. Select Don’t Aggregate from Advanced Options.
4. Remove the column you created in step 2.

104 | P a g e Copyright © 2020 Leila Gharani


Learn More

More Resources
Power Query Learn More

MORE RESOURCES
In addition to this Solution book, we’ve also put together a Power Query Reference book. In the
Reference book you’ll get more details about how you can use each Power Query feature. This book is
also available as a resource inside your online Power Query course on XelPlus.com.
Let's talk about more learning.
On my site, you’ll find weekly Excel articles on different aspects of Excel: XelPlus.com/tutorials/
There are a lot of great Excel websites out there. For more Excel information, check out my list of
resources here: XelPlus.com/resources
The more you know of Excel the easier it gets for you to implement complex projects.
If you're interested to become more advanced and create great visualizations or effective dashboards,
check out my other courses: https://www.xelplus.com/courses.
I also share weekly tutorial videos on my YouTube channel so make sure you check it out if you're
interested to learn more. Just type in Leila Gharani on YouTube.
I wish you the best of luck on your journey and hope to see you in my other courses.

Copyright © 2020 Leila Gharani 107 | P a g e

You might also like