Data Transformation
Advanced techniques for transforming and shaping data
What You'll Learn
- Advanced text transformations
- Working with dates and numbers
- Conditional columns
- Custom columns with formulas
- Unpivot and pivot operations
Text Transformations
Uppercase/Lowercase
Standardize text:
- Select text column
- Transform > Format
- Choose:
- UPPERCASE
- lowercase
- Capitalize Each Word
Trim and Clean
Remove extra spaces:
- Select column
- Transform > Format > Trim
Removes leading/trailing spaces
Clean: Removes non-printable characters
Extract Text
Get first 3 characters:
- Select column
- Transform > Extract > First Characters
- Enter count: 3
Other extracts:
- Last Characters
- Range (characters 2-5)
- Text Before Delimiter
- Text After Delimiter
Example: Extract "ABC" from "ABC-123"
- Extract > Text Before Delimiter: "-"
Replace Values
Replace "N/A" with blank:
- Select column
- Home > Replace Values
- Value to Find: N/A
- Replace With: (leave empty)
Find/Replace: Case sensitive option available!
Number Transformations
Rounding
Round to 2 decimals:
- Select number column
- Transform > Round
- Choose:
- Round Up
- Round Down
- Round (standard)
Decimal Places: Transform > Round > 2
Standard Math
Multiply column by 1.1:
- Select column
- Transform > Standard > Multiply
- Enter: 1.1
Operations:
- Add
- Subtract
- Multiply
- Divide
- Percentage
- Percent Of
Statistics
Add % of total:
- Select column
- Transform > Statistics
- Choose operation:
- Sum
- Average
- Median
- Min/Max
- Count
Adds result as new column!
Date Transformations
Extract Date Parts
Get year from date:
- Select date column
- Transform > Date > Year
Creates new column with year only!
Available parts:
- Year
- Month (number or name)
- Day
- Quarter
- Week of Year
- Day of Week
Date Calculations
Days until today:
- Add Column > Custom Column
- Formula:
Duration.Days(DateTime.LocalNow() - [DateColumn])
Age of transaction: Easy date math!
Conditional Columns
Create columns based on logic.
Simple IF
Add "High/Low" based on sales:
- Add Column > Conditional Column
- New column name: "Category"
- IF [Sales] >= 1000 THEN "High"
- ELSE "Low"
Multiple Conditions
Add "High/Medium/Low":
- Add Column > Conditional Column
- IF [Sales] >= 1000 THEN "High"
- ELSE IF [Sales] >= 500 THEN "Medium"
- ELSE "Low"
Click "Add Clause" for more conditions!
Custom Columns
Write your own formulas!
Basic Formula
Full Name from First + Last:
- Add Column > Custom Column
- Name: "FullName"
- Formula:
[FirstName] & " " & [LastName]
& is concatenation (join text)
Number Formula
Profit = Revenue - Cost:
- Add Column > Custom Column
- Name: "Profit"
- Formula:
[Revenue] - [Cost]
Using Functions
Uppercase first name:
Formula: Text.Upper([FirstName])
Get year:
Formula: Date.Year([OrderDate])
Common functions:
- Text.Upper(), Text.Lower()
- Text.Length()
- Number.Round()
- Date.Year(), Date.Month()
Unpivot Columns
Transform wide data to long format.
Wide format (bad for Power BI): Product | Jan | Feb | Mar Apple | 100 | 150 | 200 Orange | 80 | 90 | 110
Long format (good!): Product | Month | Sales Apple | Jan | 100 Apple | Feb | 150 Apple | Mar | 200 Orange | Jan | 80
How to Unpivot:
- Select month columns (Jan, Feb, Mar)
- Transform > Unpivot Columns
Result: Attribute (month) + Value (sales) columns!
Pivot Columns
Transform long to wide (opposite of unpivot).
When to use: Creating summary tables
How to Pivot:
- Select column to pivot
- Transform > Pivot Column
- Choose values column
- Choose aggregation (Sum, Count, etc.)
Group By
Create summaries.
Total sales by product:
- Transform > Group By
- Group by: Product
- New column: TotalSales
- Operation: Sum
- Column: Sales
Creates summary table!
Append Queries
Stack tables vertically (union).
Combine Jan + Feb + Mar sales:
- Home > Append Queries
- Select tables to combine
- Click OK
Tables must have same columns!
Merge Queries
Join tables (like SQL JOIN).
Add customer names to orders:
- Home > Merge Queries
- Select Orders table
- Select CustomerID column
- Select Customers table
- Select CustomerID column
- Choose join type:
- Left (all orders)
- Inner (matching only)
- Right (all customers)
- Full Outer (everything)
- Expand new column to see customer data
Try This Exercise
Transform sample data:
- Create table with:
- FirstName, LastName
- Sales amount
- OrderDate
- In Power Query:
- Add FullName (custom column)
- Add Year from OrderDate
- Add Category (High/Low) based on sales
- Round sales to whole number
- Close & Apply
Best Practices
Clean early: Filter and remove columns at the start
Use descriptive names: Rename columns clearly
Test formulas: Preview results before applying
Avoid complex formulas: Break into multiple steps
Document: Right-click step > Properties > add notes
Next Steps
Now let's learn how to build proper data models with relationships!
Tip: Most transformations can be done in multiple ways. Choose what makes sense to you!