Skip to the workspace
Pebellslearn by building
M Language Basics  ›  Lesson

Changing Text and Splitting Columns

Changing Text 12 minClean text by trimming spaces first, fixing case second and splitting last, using the Transform tab to change a column in place or the Add Column tab to keep the original.

power bi / Changing Text and Splitting Columns

Explore each scene at your own pace.

01 · The rule

The rule

Changing Text and Splitting Columns

The Mumbai till lets cashiers type product names freely, so the export holds "masala chai ", "MASALA CHAI" and "Masala Chai". To Power BI those are three different products, each with its own small slice of revenue. On top of that, the branch column arrives as S2-Mumbai, with a code and a city glued together.

The rule

Trim first, fix the case next, split last.

The text tools sit under Transform → Format and, for new columns, Add Column → Format:

Button M function " masala CHAI " becomes
Trim Text.Trim "masala CHAI"
lowercase Text.Lower " masala chai "
UPPERCASE Text.Upper " MASALA CHAI "
Capitalize Each Word Text.Proper " Masala Chai "
Clean Text.Clean removes hidden control characters, such as line breaks

Trim removes spaces from the start and end only; spaces between words stay. Capitalize Each Word does not trim, which is why the order matters.

In M, both fixes fit into one step. Inside each, the underscore _ stands for the current value:

= Table.TransformColumns(#"Changed Type", {{"Product", each Text.Proper(Text.Trim(_)), type text}})

Split Column (on the Transform tab) breaks one column into several:

  • By delimiter, at the left-most, the right-most or each occurrence of a character such as -.
  • By number of characters, or at fixed positions.
  • Into new columns (the default) or into new rows.

Splitting S2-Mumbai by - gives S2 and Mumbai, in columns named Store.1 and Store.2 until you rename them. If you only need one part, Add Column → Extract → Text Before Delimiter does it without touching the original (Text.BeforeDelimiter in M).

Every tool exists twice. On the Transform tab it changes the column in place. On the Add Column tab it builds a new column and leaves the original alone.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.