Data Cleaning and Transformation Using Power Query
This module teaches learners how to clean, shape, and transform data using Power Query in Power BI Desktop. Students will understand core transformations, manage applied steps, use the Advanced Editor for M code, and follow best practices for creating clean, reusable datasets. Hands-on exercises reinforce practical application.
1. Removing Rows and Columns
Remove unnecessary rows or columns to reduce dataset size and improve performance.
Example:
- A dataset contains empty rows and a “Notes” column that is not required. Use “Remove Rows” to delete blank rows and “Remove Columns” to drop the “Notes” column.
2. Splitting Columns
Split a column into multiple columns based on delimiter, number of characters, or positions.
Example:
- Column “Full Name” = “John Doe”
- Split by space → Columns: “First Name” = John, “Last Name” = Doe
3. Changing Data Types
Ensure data is in the correct type for calculations and visuals.
Example:
- “Order Date” column stored as text → Convert to Date type
- “Sales Amount” stored as text → Convert to Decimal Number
4. Merging and Appending Tables
- Merge: Combine tables horizontally based on a key
- Append: Combine tables vertically
Example Merge:
- Orders table + Customer table → Merge on Customer ID to get customer details for each order
Example Append:
- January sales + February sales → Append to get combined dataset
5. Conditional Columns
Create new columns based on logical conditions.
Example:
- Column “Sales Category”:
- If Sales > 10000 → “High”
- If Sales 5000–10000 → “Medium”
- Else → “Low”
6. Pivoting and Unpivoting Data
- Pivot: Transform rows into columns for aggregation
- Unpivot: Transform columns into rows for analysis
Example Pivot:
- Rows: Product and Month
- Pivot Month column → Columns: Jan, Feb, Mar
Example Unpivot:
- Columns: Jan, Feb, Mar → Rows: Month column with values
7. Applied Steps and Advanced Editor (M Code Basics)
- Applied Steps: Track all transformations sequentially for easy editing or rollback
- Advanced Editor: View and edit M code directly for complex transformations
Example:
- Applied Steps: Imported CSV → Removed columns → Changed data types
- Advanced Editor allows editing the same steps in M code to apply changes programmatically
8. Best Practices for Data Transformation
- Remove unnecessary rows and columns early
- Rename columns clearly for readability
- Document transformation logic in Applied Steps
- Keep transformations reusable for future datasets