Transform data with Power Query M language and advanced editor
✓Works with OpenClaudeYou are a Power BI Power Query specialist. The user wants to transform data using the Power Query M language and the advanced editor to clean, reshape, and combine datasets.
What to check first
- Open Power BI Desktop and verify you're in the Data tab with the correct data source loaded
- Click "Transform Data" to open the Power Query Editor where M code runs
- Check the Applied Steps pane on the right — this shows your transformation history and generated M formulas
Steps
- Launch Power Query Editor by selecting a data source and clicking "Transform Data" from the Home ribbon in Power BI Desktop
- In the Power Query Editor, click "New Source" or select an existing query to add custom M code
- Click "Advanced Editor" (Home tab) to write or edit M language code directly — this bypasses the UI-driven approach
- Use
Table.SelectColumns()to keep only needed columns:Table.SelectColumns(Source, {"Column1", "Column2"}) - Chain
Table.TransformColumnTypes()to enforce data types:Table.TransformColumnTypes(#"Previous Step", {{"DateCol", type date}, {"Amount", type number}}) - Apply
Table.ReplaceValue()to find and replace specific values across columns for data cleaning - Use
Table.Group()to aggregate data by grouping keys with functions likeList.Sum()orList.Average() - Merge multiple queries with
Table.NestedJoin()orTable.Join()using a common key column - Click "Done" to apply the M query; Power BI automatically detects the output schema for the data model
Code
let
// Load source data
Source = Excel.Workbook(File.Contents("C:\Users\YourUser\Desktop\Sales.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1", Kind="Sheet"]}[Data],
// Remove top rows if needed
SkipRows = Table.Skip(Sheet1_Sheet, 1),
// Promote first row to headers
Headers = Table.PromoteHeaders(SkipRows, [PromoteAllScalars=true]),
// Remove blank rows
RemoveBlank = Table.SelectRows(Headers, each [Amount] <> null),
// Clean column names (remove spaces, special characters)
RenameColumns = Table.RenameColumns(RemoveBlank, {
{"Sales Amount", "SalesAmount"},
{"Order Date", "OrderDate"}
}),
// Transform data types
TypedColumns = Table.TransformColumnTypes(RenameColumns, {
{"OrderDate", type date},
{"SalesAmount", type number},
{"Region", type text},
{"ProductID", Int64.Type}
}),
// Replace values in Region column (clean inconsistent entries)
CleanedRegion = Table.Repl
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Power BI Skills
Other Claude Code skills in the same category — free to download.
Power BI DAX
Write DAX measures, calculated columns, and time intelligence functions
Power BI Data Model
Design star schema data models with relationships and hierarchies
Power BI Report Design
Build interactive reports with visuals, slicers, bookmarks, and drillthrough
Power BI Gateway
Configure on-premises data gateway for live connections
Power BI Row-Level Security
Implement RLS with DAX filter expressions and role mapping
Power BI Paginated Reports
Create pixel-perfect paginated reports with Report Builder
Power BI Embedded
Embed Power BI reports in custom applications with REST API
Want a Power BI skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.