Splitter.SplitTextByRanges

Splitter

Returns a splitter function that extracts substrings from text at specified {offset, length} ranges.

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

Syntax

Splitter.SplitTextByRanges(ranges as list, optional startAtEnd as nullable logical) as function

Parameters

NameTypeRequiredDescription
rangeslistYesA list of two-element lists {offset, length}, each specifying a zero-based start position and character count for a segment.
startAtEndlogicalNoWhen true, offsets are measured from the end of the string. Defaults to false.

Return Value

functionA function that extracts substrings from text according to the list of {offset, length} pairs.

Remarks

Splitter.SplitTextByRanges returns a splitter function that extracts non-contiguous or overlapping portions of a text value based on {offset, length} pairs. Each range specifies where to start (zero-based offset) and how many characters to take.

Unlike Splitter.SplitTextByPositions (which splits at cut points) or Splitter.SplitTextByLengths (which takes consecutive segments), this function allows arbitrary, possibly non-adjacent ranges. Ranges may overlap or leave gaps between them.

This is useful when dealing with fixed-width formats where only specific columns are needed, or when fields are interspersed with padding characters that should be skipped.

Examples

Example 1: Extract two non-adjacent ranges

Splitter.SplitTextByRanges({{0, 3}, {5, 4}})("ABCDE12345")
Result
Result
1ABC,2345

Example 2: Extract named fields from a fixed-width record

let
    record = "SMITH     JOHN      1985",
    splitter = Splitter.SplitTextByRanges({{0, 10}, {10, 10}, {20, 4}}),
    parts = splitter(record)
in
    parts
Applied Steps

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

Result
1SMITH ,JOHN ,1985

Example 3: Use with Table.SplitColumn

Table.SplitColumn(
    #table({"Data"}, {{"ABCXYZ"}}),
    "Data",
    Splitter.SplitTextByRanges({{0, 3}, {3, 3}}),
    {"Part1", "Part2"}
)
Result
Part1
Part2
1ABCXYZ

Compatibility

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