Sub topic 3
Splitting and Merging Columns
Assume you know Power BI tables, basic data types, and how to open the Power Query Editor. This chapter focuses on shaping data for a model.
Split and merge columns
Use Split Column when one field contains multiple values. Choose a delimiter, such as a space or comma, or split by character position. Use Merge Columns when separate fields must become one value, such as a display name or key.
let
Source = #table(
{"FullName", "Amount"},
{{"Ada Lovelace", 1500}, {"Alan Turing", 300}}
),
SplitName = Table.SplitColumn(
Source, "FullName",
Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv),
{"FirstName", "LastName"}
),
AddedSize = Table.AddColumn(
SplitName, "OrderSize",
each if [Amount] >= 1000 then "Large" else "Small",
type text
),
MergedName = Table.CombineColumns(
AddedSize, {"FirstName", "LastName"},
Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),
"DisplayName"
)
in
MergedNameA conditional column uses rules such as if ... then ... else. A custom column lets you write an M expression directly. Check nulls before using text or numeric operations.
Unpivot cross-tab data
Cross-tab data stores categories as columns. Power BI usually works better when each category becomes a row. Unpivot converts columns into attribute-value pairs.
Select identifier columns, then choose Unpivot Other Columns. The result supports filtering, grouping, and time-based analysis.
Combine and organize queries
Append stacks rows from compatible tables. Merge joins tables using matching key columns. Keep source queries unchanged when possible. Create a staging query, then create a reference from it for each final table. Parameters store reusable values such as a folder path or date boundary.
> callout note > Merge requires compatible key values. Clean types and text before joining, or matching rows may be lost.
Keep cleaning fast
Query folding lets Power Query send transformations back to a source system, such as SQL Server. Apply filters and column selection early. Avoid unnecessary custom functions and steps that prevent folding. For files such as CSV, folding is usually unavailable, so reduce rows and columns before expensive transformations.
Close, apply, and refresh
Choose Close & Apply to load the query result into the Power BI model. Later, Refresh reruns the source and every transformation step. Review errors after refresh because a changed source schema can break a split, merge, or type conversion.
Exercise
When should you append queries instead of merging them?
Show answer
Append queries when they have similar columns and you need more rows. Merge queries when you need to add columns by matching a key.