Learn with Yasir

Share Your Feedback

Power Query in Excel: Data Cleaning and Transformation


Learn Microsoft Excel Power Query to import, clean, transform, merge, and automate data preparation from multiple sources with practical examples and step-by-step tutorials.

What is Power Query in Excel?

Power Query is a data import, cleaning, transformation, and preparation tool built into Microsoft Excel.

It helps you collect data from different sources, clean messy data, combine multiple files, and prepare information for analysis — without manually editing every row.

Think of Power Query as a data-cleaning assistant that automates repetitive Excel tasks.

[!May the Power Be with You with Power Query in Excel (With Instructional Video) Microsoft Community Hub](https://images.openai.com/static-rsc-4/emvDzFAbvDqTxmL4iDfTsH4iAQXv00f3uQFSmKkKh6xQPA8IrMIxRSJNZeyYTLM2YRdY8lqoUda88I63flK-MhyJ-xjCbEh1dWU_V6h2zW7n3awqSESOmXpZxN4LUMgcep1GREKWCjrbP-1M6BVTswdHUgsd0zugcYOAWKx-hqk?purpose=inline)

techcommunity.microsoft.com

1. Why do we use Power Query?

Suppose your university receives student admission data from different departments in separate Excel files.

You need to:

  • Combine all department files into one dataset.
  • Remove duplicate student records.
  • Remove blank rows.
  • Correct column names.
  • Change data types.
  • Filter students by department.
  • Prepare a final report.

Without Power Query, you might perform these tasks manually every time.

With Power Query, you create the process once and refresh it whenever new data arrives.

2. What can Power Query do?

Feature Purpose
Import Data Import Excel, CSV, text, PDF and database data
Remove Duplicates Remove repeated records
Filter Rows Display selected records
Split Columns Separate names, codes or values
Merge Queries Join two tables using a common column
Append Queries Combine rows from multiple tables
Replace Values Replace incorrect or unwanted values
Group By Calculate totals, counts and averages
Change Data Types Convert text, dates and numbers
Refresh Data Repeat transformations when source data changes

3. How to open Power Query in Excel

Follow these steps:

!Bot Verification

Step 1: Open Excel

Open your Excel workbook and select the Data tab.

[!The Ultimate Guide to Merging Spreadsheets by Love Spreadsheets Medium](https://images.openai.com/static-rsc-4/6gcJ-CbzBUGasbBde5nX3TUy9LyzDkfz8nIfrTC148sOnN4gtlb58xwkLax3lwdrDAIHxEmfkaBPJFiPn3fCbhLhEIi8_wIRDzDmkptfzSQG5Yuu-bm12AewxmNjVtBnEtcZ6eCYngqM0petmsPG57oOM9hTmrY-6ZJJn-EK9bs?purpose=inline)

Step 2: Import data

Select Get Data → From File → From Workbook.

You can also import CSV files, databases and other sources.

[!Create a data type (Power Query) Microsoft Support](https://images.openai.com/static-rsc-4/8yp0OeEwe5oqrTTxXsdbOp2ez3PlKF0skGk_ZZzUtls-lUXc0d1n77Pkc39hNHLD8RIeLs43sYA42_X_Olg-bGiY8cDus4yH_xZLSMABaAJNSkmtApKA3sLowfRO2d2qcr3y2y7ewqj7nyrrkNindbkz98ZlZf4uB_SYlAuEA-k?purpose=inline)

Step 3: Select your data

Select the required worksheet or table and click Transform Data.

[!Cómo eliminar duplicados en Excel: 5 mejores métodos DataCamp](https://images.openai.com/static-rsc-4/_P59zZ6uy8gLgZ1e__eJaO88J-7mDbCEn2y4BGnhplTLhGfs36OBN3awYP7XpAV6UdGls6tGPDRv1cBozNUhi7nciCXrr8Pv-xScYLtU8vbidgxVIuX-_bHZxNLehuNQAWSwfK7oL-PNeyIKvejadvTsNDC_iv8B5gNCTY6zpp8?purpose=inline)

Step 4: Clean your data

Use the Power Query Editor to remove duplicates, filter records, rename columns and change data types.

!Join two or more tables in Excel with Power Query

Step 5: Load the results

Select Home → Close & Load to send the transformed data into Excel.

4. Practical example: Clean student data

Suppose you have this dataset:

Student ID Student Name Department Marks
101 Ali CS 85
102 Ahmed IT 72
103 Sara CS 90
101 Ali CS 85
104 Ayesha IT  

You want to:

  1. Remove duplicate student records.
  2. Remove rows with missing marks.
  3. Filter students from the CS department.
  4. Load the cleaned data into Excel.

Expected result:

Student ID Student Name Department Marks
101 Ali CS 85
103 Sara CS 90

You can perform all these operations through Power Query without writing code.

5. Understanding the Power Query Editor

Power Query in Excel - Basics, Examples, How to Use?

excelmojo.com

The editor has three important areas:

  1. Queries Pane: Displays all imported queries.
  2. Data Preview: Displays your data and allows transformations.
  3. Applied Steps: Records every transformation you perform.

The Applied Steps feature is particularly useful. Power Query remembers your operations and automatically repeats them when you refresh the data.

6. What is the difference between Power Query and Excel formulas?

Excel Formulas Power Query
Calculate values Import and transform data
Work mainly within worksheets Work with multiple data sources
Often require copying formulas Automatically repeat saved steps
Update calculations when cells change Refresh transformations when source data changes
Examples: SUM, IF, VLOOKUP Examples: Merge, Append, Group By

7. What is M language?

Power Query uses a programming language called M (Power Query Formula Language).

When you perform transformations using the graphical interface, Power Query automatically generates M code.

For example:

= Table.RemoveDuplicates(
    Source,
    {"Student ID"}
)

This code removes duplicate records based on the Student ID column.

You can view the generated code through:

Home → Advanced Editor

8. How to refresh Power Query data

One of the biggest advantages is automatic repetition of your cleaning process.

For example:

  1. You import student data.
  2. You remove duplicates and blank records.
  3. You load the cleaned data into Excel.
  4. Later, you add new students to the original source file.
  5. Select Data → Refresh All.

Power Query repeats your previously defined transformations and updates the output.

[Salesforce Data Series — Part 2 — Connecting Your Data to Excel in Windows by Corey Rastello Medium](https://images.openai.com/static-rsc-4/3YfWlaTqpWPyE_Wm7jINvFNVoF1m_eIQPAaCuZq-suA96mqeo9jaKSrxkFW5v7FOPMRQBSRXao5e0i8nuDXWIIGUjdZ4e0Eb7_uYhHXFORWyIIFaM9OZW2CzhzLy52JdScZtdCLfex-74F93GiAS_MBV_wMgLgYvM8EW4zKoJ5g?purpose=inline)

cmrastello.medium.com

If you are learning Power Query from beginner to advanced level, follow this sequence:

Module Topics
1 Introduction to Power Query
2 Import Data from Excel and CSV
3 Understanding Power Query Editor
4 Data Cleaning and Removing Duplicates
5 Filtering, Sorting and Replacing Values
6 Splitting and Merging Columns
7 Append Queries and Merge Queries
8 Group By and Aggregations
9 Working with Multiple Excel Files
10 Introduction to M Language
11 Advanced Editor and Custom Columns
12 Data Refresh and Automation
13 Practical Data Analysis Project

References and Bibliography