Power Query M Language – Beginner Guide
🧾 Power Query M Language – Cheat Sheet (Beginner)
🔹 Basic Structure
let
StepName = SomeFunction(Source),
NextStep = AnotherFunction(StepName)
in
NextStep
🔹 Common Functions
| Purpose | Function | Example |
|-----------------|-----------------------------------|--------------------------------------------------------------|
| Import Table | Excel.CurrentWorkbook() | Excel.CurrentWorkbook()
{[Name="SalesData"]}[Content] |
| Filter Rows | Table.SelectRows | Table.SelectRows(Source, each [Amount] > 1000)
|
| Remove Columns | Table.RemoveColumns | Table.RemoveColumns(Source,
{"Column1", "Column2"}) |
| Rename Columns | Table.RenameColumns | Table.RenameColumns(Source,
{{"OldName", "NewName"}}) |
| Change Type | Table.TransformColumnTypes | Table.TransformColumnTypes(Source,
{{"Amount", type number}})|
| Sort Table | Table.Sort | Table.Sort(Source, {{"Date", Order.Ascending}})
|
| Add Column | Table.AddColumn | Table.AddColumn(Source, "NewCol", each
[Amount]*2) |
| Merge Queries | Table.NestedJoin | Used via UI or advanced manually
|
🔹 Data Types in M
- type text – text/string
- type number – numeric
- type date, type datetime
- type logical – true/false
Beginner Exercise: Filtering and Renaming
Goal:
Load a table from your Excel file and filter out rows where the "Amount" is less than 1000. Then
rename the column "Amount" to "Sales Value".
Steps:
1. Create a simple table in Excel:
| Name | Amount |
|--------|--------|
| Alice | 500 |
| Bob | 1500 |
| Carol | 1200 |
2. Give this table a name, e.g., SalesData (select table → right-click → Table Name in top-left).
3. Go to Excel → Data tab → Get Data → From Other Sources → Blank Query.
4. In the Power Query Editor, open Advanced Editor and paste this:
let
Source = Excel.CurrentWorkbook(){[Name="SalesData"]}[Content],
FilteredRows = Table.SelectRows(Source, each [Amount] >= 1000),
RenamedColumns = Table.RenameColumns(FilteredRows, {{"Amount", "Sales Value"}})
in
RenamedColumns
5. Click Close & Load to load the result back into Excel.