Power Query Tutorial - What Is It, How To Use, Full Examples, Tips & Tricks
Power Query Tutorial - What Is It, How To Use, Full Examples, Tips & Tricks
Power Query
Chandoo
Share
Power Query (Get & Transform data in Excel) is a true game changer. It can simplify and automate various
data activities. The key benefits of Power Query are,
In this Power Query Tutorial, learn what it does, how to use it with 4 practical examples, tips & tricks to
work with Power Query better.
https://chandoo.org/wp/power-query-tutorial/ 1/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Table of Contents
6.3. Power Query Example 3: Combine data from all files in a folder
Think of Power Query as your own SQL (querying) tool built in to Excel (or Power BI). Use it to manipulate,
https://chandoo.org/wp/power-query-tutorial/ 2/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
thing to remember is, Power Query is for connecting, cleaning and manipulating data. You do this by
Here is an example of Power Query editor window with 6 key areas highlighted. Click on the image to
expand.
https://chandoo.org/wp/power-query-tutorial/ 3/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
1. Ribbon: You will see the ribbons on top of Power Query editor UI. There is home ribbon where
common query options like column / row adjustments, clean-up and joins are found. The other
2. Queries Pane: This is where all the queries (or connections) you have in the workbook are
listed. You can select a query to preview its results and work on it.
3. Data view: You find the preview of current step of selected query here. As you make changes to
the data, this preview is updated. This data view looks almost like Excel spreadsheet view.
4. Query settings: You can adjust query name, see all the applied steps here. We use this to
make changes to the query or delete any steps.
5. Formula bar (optional): The optional formula bar shows corresponding M Language code for
current step. You can enable / disable this formula bar from “View ribbon”.
6. Close & Load button: This button, also shown as “Publish” in Power BI is what we use to close
https://chandoo.org/wp/power-query-tutorial/ 4/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
2. Use buttons in “Get & transform data” area to make a new connection.
3. Or click on buttons in “Queries & Connections” area to refresh or view the existing queries.
https://chandoo.org/wp/power-query-tutorial/ 5/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
I made a 1+hour tutorial on Power Query explaining every aspect of it, along with 4 full examples. Please
Power Query Tutorial - What is it, how to use it & 4 complete examples + F
Power Query is packed with thousands of features to clean, process and manage data. That is why it is tricky
to comprehend the overall picture of it. I made a mind-map of Power Query so you can get holistic view of
this life saving tool. See it below (click on the image to enlarge).
https://chandoo.org/wp/power-query-tutorial/ 6/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
In this section, I will demonstrate how to use Power Query with four full-length examples. Each example has
sample data and completed workbook for you download and follow along.
https://chandoo.org/wp/power-query-tutorial/ 7/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Includes sample data, completed Excel workbook & Power Query Mind-map PDF
In the first Power Query example, we will look at data for one thousand staff and clean it up. The
data is in an Excel file. We will load it to Power Query and perform below clean-up activities. After data is
Whenever there are new employees, we will simply refresh the Power Query connection and it will load
new data (after apply clean-up steps) automatically. Just like magic.
The below instructions show how to do this with Excel Power Query. You can apply the same steps in Power
BI too.
Go to data ribbon and click on “From File” and select “Excel”. Point to the employee data set.
https://chandoo.org/wp/power-query-tutorial/ 8/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
there.
1. Remove top rows: The file contains 2 rows of header information which is not needed. From
“Home ribbon” in Power Query editor, using the “Remove rows” button, remove top 2 rows.
2. Promote headers: Now that our data is has no extra rows on top, let’s use row number 3 as
header. From home ribbon, just tap on the “use first row as headers” button.
3. Remove blank columns: The file also loads a few blank columns. Just use “Remove columns”
4. Replace missing values – gender & department columns: Select each column with missing
data and either right click or use “replace values” button to find & replace nulls with alternative
values.
5. Remove staff with no salary: This operation is also called “Filtering”. Just use the filter button
I have illustrated the screen buttons for these 5 data cleansing steps on Power Query UI below. Check it out
https://chandoo.org/wp/power-query-tutorial/ 9/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Power Query Tip: Plan First, Clean Next
Save a lot of time by planning all your data cleansing steps first. Think about ways in which your data could
employee. You can use “Add column” ribbon of Power Query to do such operations.
For example, to extract “USA” from the address “1 Infinite Loop, Los Angels, CA, USA“, we can use text
after delimiter option.
To extract the country, select the address column and use Add Column > Extract > Text After Delimiter
option.
Note: In the video, I use a more advanced version of this as our addresses are not so straight forward.
https://chandoo.org/wp/power-query-tutorial/ 10/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
You can use similar approach to add “year” from date of join.
as a table. You can use this table for data analysis or reports.
How to refresh:
Whenever there is new data added to the employee data file, just head over to the Excel file with connection
and refresh it (shortcut: Ctrl+Alt+F5 will refresh all connections)
leave it in the query editor. If you do not load a table, you can still have it refreshable
for calculation purposes.
https://chandoo.org/wp/power-query-tutorial/ 11/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
In this example, let’s use Power Query to scrape web data from List of Indian States page on Wikipedia.
On that page, there is a historical census data table (depicted below) and we will connect to it from Power
Query. Once we have the data, we will unpivot it to tabular format for easy analysis.
https://chandoo.org/wp/power-query-tutorial/ 12/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
https://en.wikipedia.org/wiki/List_of_states_in_India_by_past_population
and connect.
Power Query will show all the tables on the web page. Select the census table and click on “transform”
button.
https://chandoo.org/wp/power-query-tutorial/ 13/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
then your Power Query connections will break. It is a good idea to check such
connections once in a while to make-sure they are working.
URL parameters: You can use “Advanced” option during connection time to set up URL
parameters or variables. This gives you flexibility to access things like page 5 of a result
set.
Query [Advanced]
https://chandoo.org/wp/power-query-tutorial/ 14/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
You can use “folder” connection option in Power Query to easily consolidate data from all files in a folder.
In the third example, we will take all the project files in the example dataset and combine data to one table.
This process is a bit clumsy to explain in text alone. So please watch the video segment (timestamp 58:48)
to understand this fully. I am providing a summary of the folder combine technique below.
1. Start by making a folder connection (Data ribbon > Get Data > From File > From Folder)
4. Or choose “Combine & Transform” option for customizing the transformation process.
5. Power Query will show one of the files and asks you how you want to extract data. Based on
your selection, PQ will apply the same logic to all files and combines the data for you.
In the last example of Power Query, we will learn how to merge and append tables. These are similar to
SQL operations.
https://chandoo.org/wp/power-query-tutorial/ 16/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
In that case, Power Query will still merge, by including all columns. The missing values will be shown as null
in the final appended table.
https://chandoo.org/wp/power-query-tutorial/ 17/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Follow the screen prompts and specify the second table name.
Power Query will append second table at the end of first table.
You can also use this to append more than two tables.
Students Table
Student ID
Name
Date of birth
Class
Parent 1 name
Parent 2 name
Course Table
Course ID
Course name
Instructor
Credits
Enrollment Table
Course ID
Student ID
https://chandoo.org/wp/power-query-tutorial/ 18/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Follow screen prompts and select common column (field) between both source and target
tables.
Specify the join type. Leave the default “left outer join” if you just want matching values in
target table when present. Try other kinds of join (merge) if you need.
Power Query will perform the merge and show corresponding rows of target table as a new
column.
Please use below button to download all Power Query examples, sample data and mind-map PDF.
Includes sample data, completed Excel workbook & Power Query Mind-map PDF
Tip #1
Tip #2
Tip #3
https://chandoo.org/wp/power-query-tutorial/ 19/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Tip #4
Tip #5
More..?
I recommend the excellent Collect, combine and transform data using Power Query book by Gil
Raviv.
If you want a comprehensive and hands-on data analysis course with plenty of Power Query examples,
Welcome to Chandoo.org
Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing
videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel,
Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.
https://chandoo.org/wp/power-query-tutorial/ 20/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
24 Comments
Ask a question or say something...
Tagged under append tables, consolidation, downloads, merge tables, no ads, power query, solo, videos,
web scraping
These are my absolute favorite helpful websites that frequently write about Power Query. Please
bookmark
PREVIOUS and enjoy.
Project Plan – Gantt Chart with drill-down capability [Templates]
NEXT
Excel formula to convert calendar format to table
Excel Guru blog by Ken Puls – For Power Query tips, practical scenarios and guidance.
24 Responses to “Power
Cross Join blog Query
> PowerTutorial – What
Query pages is it,
by Chris How
Webb – forto use, Fulltoexamples,
intermediate advanced PQTips
& Tricks” applications.
M language primer (multi-part series) for advanced users by Ben Gribado
1. RonPower
MVP (2012-2018)
Query best says:
practices [Microsoft Docs]
August 27, 2020 at 12:28 am
Leave
Chandoo
analysis
says:
with Power Query
August 27, 2020 at 2:32 am
Folder consolidation – advanced example
Thank you Ron. I am glad you liked this and will be sharing the link with others
Oddly shaped data to table – with Power Query
I used
Moremindmup online
on Power Queryservice to create this. I fixed the image link, it should expand now.
Reply
I've recreated the example diagram for the table organization in Example 4 in PowerPivot diagram view:
https://1drv.ms/u/s!Am8lVyUzjKfppCGnREimjqw2u838?e=FKgDTm
Reply
Chandoo says:
September 2, 2020 at 2:15 am
Good suggestions Ron. I have included a snapshot of how column profiles look to the article. I will
revise the mind-map when I release another update to this page. Thanks also for sharing the
image of relationship diagram.
Reply
3. abhay says:
https://chandoo.org/wp/power-query-tutorial/ 21/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
I tried by removing column and query style from query but still it is not helpful
pl suggest
Reply
Chandoo says:
September 2, 2020 at 2:14 am
Reply
Hi Chandoo,
Is it possible to use a data model created in one workbook to use in another workbook?
Reply
Reply
thank you so much for this informative article. keep sharing this type of content it will really be going to
help the student.
Reply
Hi Chandoo!
I love the mind map! I would like to get a large laminate board made from it, but the printer lab said the
resolution won't work to enlarge it to what I would love to have. Is it possible you might have a high
resolution version? You are a great teacher by the way. Cheers from Canada.
Reply
DAX is a hard nut to crack,,, since syntax are bit complicated,, and without it reports are like half cooked
eggs. In general Power Query and BI are good to use,, mind mind map is good.
Reply
Thanks Chandoo, It is great that you have offered tutorials like this, it is a fantastic way to learn PQ.
Much Appreciated,
Dave
Reply
https://chandoo.org/wp/power-query-tutorial/ 22/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
9. Suhas says:
April 21, 2021 at 5:58 pm
Reply
Many thanks for a thoughtfully produced, well structured and evenly paced video and supporting
material. Professional and approachable.
Reply
I have followed the steps to complete the Example 1 Load and Clean-up, but was not sure how to
complete the step Replace alternative values in the Gender and Department columns. Do you have to
view each record to replace the data, and how would you know which department to replace the null
with?
Reply
Hi Chandoo, I am a 66 year old man and I have a rudimentary knowledge of computers. I was able to
follow your tutorial on PQ and now I am trying to do some exercises. I sincerely thank you for this
tutorial.
M.Shiva Kumar,
Mysore, India
Reply
Hi Chandoo,
thank you very much for this easy-to-understand tutorial.
I only face one problem: when I select a folder via data/new query/from file/from folder the navigator
window does not open but I am led directly to power query with no possibilities to click combine,
transform or load.
When using the other data sources (from workbook etc) everything works well. Do you or anybody else
have an idea to fix this problem?
Best regards
Reply
Reply
https://chandoo.org/wp/power-query-tutorial/ 23/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Reply
Great Job team... very detailed information provided by you. Thanks a lot.
Reply
Reply
hi there - any advice on how to pull in the comments from individual cells when using power query to
combine data from tables in multiple sheets?
Reply
Hi Chandoo,
Thanks for your useful session, it helps to understand and learn PQ easily. i really appreciate your great
effort.
Actually i had an issue with the excel file by using FROM FILE which is downloaded from salesforce report
. unfortunately, it shows an error msg "External table is not in the expected format." while importing into
EXCEL.
I'm not sure what is an actual issue with this salesforce report file [if i tried to open it in normal way in
excel it shows this msg "the file format and extension of report report1652849835532.xls don't match
the file could be corrupted or unsafe. do you want to open it anyway?" it gets open successfully after
given "YES"]
Best regards
Shan
Reply
Finally I found the right place to learn the right skills for excel, many thanks Chandoo for free support
that for the whole world
For myself these steps are new for a beginner in data analysis work.
Best regards,
https://chandoo.org/wp/power-query-tutorial/ 24/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
Reply
Leave a Reply
Yes, sign me up
Power BI
ABOUT DOWNLOADS
My Story 20+ Excel Templates
© All rights reserved.
https://chandoo.org/wp/power-query-tutorial/ 25/26
09/01/23, 18:56 Power Query Tutorial - What is it, How to use, Full examples, Tips & Tricks
https://chandoo.org/wp/power-query-tutorial/ 26/26