Splitter.SplitTextByPositions

Splitter

Returns a splitter function that divides text at the specified zero-based character positions.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Splitter.SplitTextByPositions(positions as list, optional startAtEnd as nullable logical) as function

Parameters

NameTypeRequiredDescription
positionslistYesA list of zero-based character positions at which to split the text. The first position is typically 0 to include the text from the start.
startAtEndlogicalNoWhen true, positions are counted from the end of the string. Defaults to false.

Return Value

functionA function that splits text at each specified character position.

Remarks

Splitter.SplitTextByPositions returns a splitter function that, when applied to a text value, slices the text at each position in the positions list. Each position defines the start of the next segment.

The positions list should be in ascending order. Typically the first element is 0 to start from the beginning of the string. Each subsequent position marks where the next segment begins. Text between consecutive positions forms one segment.

This is useful for parsing fixed-width formats where you know the column start positions rather than the lengths.

Note the difference from Splitter.SplitTextByRanges: positions defines cut points, while ranges specifies {offset, length} pairs.

Examples

Example 1: Split at positions 0, 2, and 5

Splitter.SplitTextByPositions({0, 2, 5})("ABCDEFGH")
Result
Result
1AB,CDE,FGH

Example 2: Parse a fixed-width record with known column starts

let
    record = "JohnDoe  30M",
    splitter = Splitter.SplitTextByPositions({0, 8, 10}),
    parts = splitter(record)
in
    parts
Applied Steps

The final output — a list of the three positional segments extracted from the fixed-width record.

Result
1JohnDoe ,30,M

Example 3: Use with Table.SplitColumn

Table.SplitColumn(
    #table({"Record"}, {{"NY10001"}}),
    "Record",
    Splitter.SplitTextByPositions({0, 2}),
    {"State", "ZipCode"}
)
Result
State
ZipCode
1NY10001

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks