Select and transform columns
Choose rows and columns for a defined purpose
A transformation changes a table into another value. Selection of rows changes which observations are included; selection of columns changes which attributes remain. First decide the required grain, key and output schema. Retain the raw query or source snapshot; a filtered report input is not the same thing as a data-quality reject table. All examples are standalone blank-query expressions for Power Query M in a disposable Power BI Desktop file. No external source or account is needed. Results are predicted, not native execution evidence; exact Desktop build NOT RUN.
Select, type and label a valid subset
let Raw = #table(type table [ID = text, Qty = text, State = text, Note = text], {{"001", "2", "Open", "a"}, {"002", "5", "Closed", "b"}, {"003", "0", "Open", "c"}}), Selected = Table.SelectRows(Raw, each [State] = "Open"), Projected = Table.SelectColumns(Selected, {"ID", "Qty"}), Typed = Table.TransformColumnTypes(Projected, {{"Qty", Int64.Type}}, "en-US"), Labeled = Table.AddColumn(Typed, "StockState", each if [Qty] = 0 then "Empty" else "Available", type text)in LabeledExpected rows: 001 | 2 | Available, 003 | 0 | Empty. ID remains text and keeps its zeros. Quantity is a whole number. Record 002 is outside the requested business scope, not invalid. The conditional column evaluates against each row. SelectColumns defines the output column sequence.
Apply a function to a column value
let Source = #table(type table [ID = text, Label = nullable text], {{"01", " North "}, {"02", null}, {"03", "South"}}), Clean = Table.TransformColumns(Source, {{"Label", each if _ = null then null else Text.Trim(_), type nullable text}}), Output = Table.ReorderColumns(Clean, {"Label", "ID"})in OutputExpected column order Label, ID; rows North/01, null/02, South/03. The function receives the current cell, unlike the row record received by Table.AddColumn. TransformColumnTypes invokes type conversions; TransformColumns lets you define custom behavior and declare the output type. Reordering is presentation/schema work, not sorting rows.
Protect the schema
A missing required ID must fail rather than silently become null. SelectColumns normally errors on a missing column; its optional MissingField.UseNull is appropriate only for explicitly optional fields. A renamed field or newly added month requires a schema review. Never use MissingField.Ignore on mandatory keys just to make refresh succeed. If parsing can fail, retain raw text, classify errors with try, and partition rejected rows before loading. Do not apply Int64.Type to arbitrary decimal quantities without checking the business rounding rule.
Practice: keep zero quantities
Change the first fixture so row 002 is Open and row 003 remains zero. Predict the output IDs, row count and sum of Qty. Then remove the ID column from the input and explain why the required projection must fail. Do not change the raw query to hide the failure.