Power Query
Power Query
The tutorial delves into practical real-life scenarios of using Power Query in Excel.
In the previous article, we laid the groundwork by exploring the basics of Excel Power Query. Now, it’s
time to put it to use in real-world scenarios. Below, you will find a number of examples that will guide
you through the effective applications of PQ in everyday situations.
The examples assume that you have already imported your source data to the Power Query Editor. If
not, you can easily catch up by revisiting our previous tutorial that details how to get data into Power
Query.
To make it easy for you to follow along, we've prepared a sample workbook that you can download at
the end of this post. Let's start our data journey and see how Power Query works in action!
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 1/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 2/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
Remove Duplicates.
1. Remove case-sensitive duplicates as explained above. Alternatively, you can select and right-click
the column that you want to dedupe, and then choose Remove Duplicates from the context menu.
2. In the Formula Bar, add Comparer.OrdinalIgnoreCase as a comparison criterion to the second
argument of the Table.Distinct function.
In our case, after doing the standard remove duplicates operation, the Table.Distinct function looked
like this:
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 3/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
It successfully removed all the rows with the names in column A that were exactly the same, but it left
some entries with variations in letter case, as shown in the screenshot below:
To fix this issue, you can add the Comparer.OrdinalIgnoreCase criterion to the function like this:
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 4/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
This will eliminate all the rows containing duplicates in column A, ignoring the letter case.
Users with advanced Excel skills can do this operation in the Advanced Editor by changing the
Removed Duplicates line to this format:
Note. Sometimes, you may have to look at more than one column to identify duplicate records. For
instance, if a person has different name variations like "Johnson, Bill" and "Johnson, William", you
can also check the Address column for duplicates.
In our sample dataset, the Registration Date column shows both date and time. To display only the
date part of the values, you need to change the data type of the column from Date/Time to Date. This
can be done in two ways:
On the Home tab, select Data Type > Date from the ribbon.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 5/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
Right-click the column header and choose Change Type > Date.
1. On the Add Column tab, in the General group, click Custom Column.
2. In the Custom Column dialog window, type a name for the new column in the corresponding box,
e.g. "Date in custom format".
3. In the Custom Column Formula box, enter the DateTime.ToText function with two arguments: the
original date column and the custom format code.
To add the original date column to the first argument, select it under Available Columns on the
right and click Insert, or double click the column name.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 6/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
For the second argument, enter the desired date format such as "dd-MMM-yy" or any other
format code.
The complete formula takes this form:
4. Click OK, and a new column with the custom date format will be added to your table.
The formula bar will show the complete formula in the M language, which will look something like
this:
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 7/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
Note.
By changing the data type, you can format the values in a more suitable way for your analysis.
Similarly, you can change other columns to different data types, such as text, number, or currency,
depending on your needs.
Split column
To split a column into two or more columns by a certain delimiter, you can use the Split Column
function. For example, to split the "Full Name" column into "First Name" and "Last Name", the steps
are:
4. Decide at which occurrence of the delimiter to separate the column: left-most, right-most or each
delimiter. If a cell has only one delimiter, any option will do. But if a cell has more than one
delimiter, then you have to choose carefully.
5. When done, click OK.
6. Right-click the header of each new column and choose Rename from the context menu to give
them appropriate names (such as "First Name" and "Last Name").
Tip. If you want to preserve the original column, then duplicate it before splitting. To do this, right-
click the column and choose Duplicate Column from the context menu. This will create a copy of the
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 9/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
column with a (2) suffix in its name. You can then split this column as described above.
For example, let’s see how to extract the country name from the Address column:
3. In the dialog box that pops up, enter the delimiter (a comma and a space ", " in our dataset).
4. Expand the Advanced option section and choose to scan for the delimiter from the end of the input,
as the country name comes after the last comma in a cell. If you need to extract a value from the
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 10/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
A new column with the extracted values will be added to the end of the table, and you can move it to
any position you want by dragging the column header.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 11/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
Picture a scenario where country names within the Address column are separated by various
delimiters like commas, spaces, or vertical bars. In such cases, you can rely on Power Query to extract
country names based on an example you provide. This is similar to how Excel's Flash Fill feature
works.
Here's how to add a new column using an example from existing columns:
1. Select the column that contains the source data (the Address column in our example).
2. On the Add Column tab, click Column from Examples > From Selection.
3. In the first row of the new column, type the country name that corresponds to the first address.
Power Query will try to infer the pattern and fill the rest of the values based on your example. If
some cells are blank or filled with incorrect values, provide another example in the second row or
any other row until Power Query gets it right.
4. When all the cells are filled with the correct values, press Ctrl + Enter to apply the changes.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 12/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
You will now have a new column that extracts the country names from the addresses.
Replace With: enter the replacement value corresponding to your data type (e.g., "0" for numeric
columns or "N/A" for text columns).
4. Click OK, and Power Query will apply the replacement to all the selected columns.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 13/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
| Else | Bronze |
4. Click OK to create the new column.
This feature is similar to writing a nested IF statement in Excel, but it’s a lot easier and more
convenient to use.
By default, the new conditional column will appear at the end of your dataset, and you can drag it to
any position you want.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 15/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 16/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
For example, to calculate the total donation amount by country and donor level, this is what you need
to do:
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 17/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
As a result, a new table will be created displaying the grouped and aggregated data. If needed, you
can sort the table by one or more columns: right-click the filter arrow next to the column name and
choose either to sort ascending or descending.
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 18/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
In this example, we get a summary of total donation amounts based on both country and donor level.
Tip. After making the necessary changes in the Power Query Editor, don't forget to load your
results into a worksheet.
That’s how to use Power Query in Excel. Now that you know the basics, go ahead and unlock more
data transforming secrets to impress your boss, colleagues, and clients with your data mastery :-)
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 19/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
9 comments
1 PCI says:
2025-02-02 at 2:25 pm
Thanks a lot, it helps me to understand more deeply what can ne done
Reply
2 Paresh says:
2025-01-29 at 4:23 am
What is meant by ABC at the left side of Header-Full name, Address?
Reply
Reply
list of payment Ordinary Hours Ordinary Paid Overtime 1.50 Hours Overtime 1.50 paid
Overtime 2.00 Hours Overtime Paid aamount Leave Hours Leave Paid Leave Loading
Hours Leave Loading paid
Ordinary Hours 5 150 0 0 0 0 0 0 0 0
Overtime 1.50 0 0 5 200 0 0 0 0 0 0
Overtime 2.00 0 0 0 0 5 400 0 0 0 0
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 20/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
and for each row I have 2 columns e.g. Ordinary hours and ordinary amount earn then
another 2 columns with Overtime 1/5 hours and Overtime amount and so on in total I
have 10 columns plus the list above.
Question: How can bring the amount of hours in one column and another column with
the amount so I can have only 3 columns in total?
and I want only 2 with all the information. eg:
=TEXTSPLIT(SUBSTITUTE(TEXTJOIN(",",TRUE,A1:K1),",0",""),",")
Copy this formula down the column as far as necessary. I hope it’ll be helpful.
Reply
Reply
5 laxmam says:
2023-10-22 at 5:14 pm
Great article, Pls give more power query example.
Reply
6 Flavio says:
2023-10-19 at 7:48 am
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 21/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
thanks for your great work. i tried to download Practice workbook for download but it
give me an error. Greatings
Reply
Reply
Post a comment
Your comment
I have read and accept the Terms of use and Privacy Policy
Send
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 22/23
5/2/25, 10:30 AM How to use Power Query in Excel with examples
https://www.ablebits.com/office-addins-blog/how-to-use-power-query-excel/ 23/23