Power Query is a powerful tool for data transformation and automation. Below are more practical examples of how you can use Power Query in your daily workflows:
1. Combine Data from Multiple Files
Scenario: You have monthly sales data saved in separate Excel files and want to combine them into a single table.
Steps:
- Go to Data > Get Data > From File > From Folder.
- Select the folder containing the Excel files.
- Power Query will display the list of files. Click Combine > Combine & Load.
- Power Query will merge all files into a single table.
- Load the data back into Excel.
Example Output: All monthly sales files (e.g., January, February) are combined into one table.
2. Remove Duplicates from a Dataset
Scenario: You have a list of customer records and want to remove duplicate entries.
Steps:
- Load your data into Power Query (Data > Get Data > From Table/Range).
- In Power Query Editor, select the columns to check for duplicates.
- Click Remove Duplicates in the Home tab.
- Load the cleaned data back to Excel.
Example Output: Original Table:
Customer ID | Name | |
---|---|---|
101 | Alice | alice@example.com |
102 | Bob | bob@example.com |
101 | Alice | alice@example.com |
Cleaned Table:
Customer ID | Name | |
---|---|---|
101 | Alice | alice@example.com |
102 | Bob | bob@example.com |
3. Split Columns Based on Delimiters
Scenario: You have a single column with full names (e.g., “John Smith”) and want to split them into First Name and Last Name.
Steps:
- Load the data into Power Query.
- Select the column to split.
- Click Split Column > By Delimiter and choose the space character (” “).
- Rename the resulting columns as “First Name” and “Last Name”.
- Load the transformed data back into Excel.
Example Output: Original Table:
Full Name |
---|
John Smith |
Jane Doe |
Transformed Table:
First Name | Last Name |
---|---|
John | Smith |
Jane | Doe |
4. Pivot and Unpivot Data
Scenario: You have sales data in a pivot table format and want to unpivot it for analysis.
Steps:
- Load your data into Power Query.
- Select the columns to unpivot (e.g., “January”, “February”).
- Click Transform > Unpivot Columns.
- Rename the resulting columns (e.g., “Month”, “Sales”).
- Load the unpivoted data back to Excel.
Example Output: Original Table:
Product | January | February |
---|---|---|
Apple | 5000 | 6000 |
Banana | 4000 | 4500 |
Unpivoted Table:
Product | Month | Sales |
---|---|---|
Apple | January | 5000 |
Banana | January | 4000 |
Apple | February | 6000 |
Banana | February | 4500 |
5. Create Custom Columns
Scenario: Add a calculated column that categorizes sales as “High” or “Low” based on a threshold.
Steps:
- Load your data into Power Query.
- Click Add Column > Conditional Column.
- Set conditions, e.g., “If Sales > 5000, then High, else Low”.
- Load the updated table back to Excel.
Example Output: Original Table:
Product | Sales |
---|---|
Apple | 6000 |
Banana | 4000 |
Transformed Table:
Product | Sales | Category |
---|---|---|
Apple | 6000 | High |
Banana | 4000 | Low |
6. Replace Values
Scenario: You want to replace incorrect or missing values (e.g., “N/A”) with actual data.
Steps:
- Load your data into Power Query.
- Select the column with the incorrect values.
- Click Transform > Replace Values and specify the old and new values.
- Load the corrected data back to Excel.
Example Output: Original Table:
Product | Sales |
---|---|
Apple | 5000 |
Banana | N/A |
Corrected Table:
Product | Sales |
---|---|
Apple | 5000 |
Banana | 0 |
7. Merge Queries
Scenario: Combine two tables based on a common column (e.g., “Product ID”).
Steps:
- Load both tables into Power Query.
- Click Home > Merge Queries.
- Choose the common column (e.g., “Product ID”) to join the tables.
- Select the type of join (e.g., Inner Join).
- Expand the merged data and load it back to Excel.
Example Output: Sales Table:
Product ID | Sales |
---|---|
P001 | 5000 |
P002 | 3000 |
Product Details Table:
Product ID | Product Name |
---|---|
P001 | Apple |
P002 | Banana |
Merged Table:
Product ID | Sales | Product Name |
---|---|---|
P001 | 5000 | Apple |
P002 | 3000 | Banana |