Anatomy of a query
let
Source = Csv.Document(File.Contents("C:\data\sales.csv"),
[Delimiter = ",", Encoding = 65001]),
Promoted = Table.PromoteHeaders(Source,
[PromoteAllScalars = true]),
Typed = Table.TransformColumnTypes(Promoted,
{{"Date", type date}, {"Amount", type number}})
in
TypedFilter and sort rows
Table.SelectRows(Typed, each [Amount] > 100)
Table.SelectRows(Typed, each [Region] = "North"
and [Date] >= #date(2026, 1, 1))
Table.Distinct(Typed, {"OrderID"})
Table.Sort(Typed, {{"Amount", Order.Descending}})
Table.FirstN(Sorted, 10)Columns
Table.SelectColumns(Typed, {"Date", "Region", "Amount"})
Table.RemoveColumns(Typed, {"Notes"})
Table.RenameColumns(Typed, {{"Amt", "Amount"}})
Table.AddColumn(Typed, "Net",
each [Amount] - [Discount], type number)Clean text
Table.TransformColumns(Typed, {
{"Customer", Text.Trim, type text},
{"Region", Text.Proper, type text}})
Table.ReplaceValue(Typed, "N/A", null,
Replacer.ReplaceValue, {"Region"})
Table.AddColumn(Typed, "Domain",
each Text.AfterDelimiter([Email], "@"), type text)Group by
Table.Group(Typed, {"Region"}, {
{"Total", each List.Sum([Amount]), type number},
{"Orders", each Table.RowCount(_), Int64.Type}})Merge (join) and append
Merged = Table.NestedJoin(Sales, {"ProductID"},
Products, {"ProductID"}, "Product", JoinKind.LeftOuter),
Expanded = Table.ExpandTableColumn(Merged, "Product",
{"Category", "Price"}),
AllYears = Table.Combine({Sales2025, Sales2026})Unpivot and pivot
// Month columns into rows: Region | Month | Amount
Table.UnpivotOtherColumns(Source, {"Region"},
"Month", "Amount")
// And back again
Table.Pivot(Long, List.Distinct(Long[Month]),
"Month", "Amount", List.Sum)Conditional columns
Table.AddColumn(Typed, "Band", each
if [Amount] >= 1000 then "Large"
else if [Amount] >= 100 then "Medium"
else "Small", type text)Errors and nulls
Table.AddColumn(Typed, "Unit price",
each try [Amount] / [Qty] otherwise null)
Table.RemoveRowsWithErrors(Typed, {"Amount"})
Table.ReplaceErrorValues(Typed, {{"Amount", 0}})
Table.SelectRows(Typed, each [Region] <> null)Dates
Date.Year([Date])
Date.StartOfMonth([Date])
Date.EndOfMonth([Date])
Date.AddMonths([Date], 1)
Date.DayOfWeekName([Date])A date table
let
Start = #date(2026, 1, 1),
Dates = List.Dates(Start, 365, #duration(1, 0, 0, 0)),
Calendar = Table.FromList(Dates,
Splitter.SplitByNothing(), {"Date"}),
Typed = Table.TransformColumnTypes(Calendar,
{{"Date", type date}})
in
TypedGood habits
On database sources, filter rows and remove columns early so the work folds back to the database (right-click a step and check View Native Query). Set data types explicitly, give steps clear names, and reference a staging query instead of duplicating it.
