Combiner.CombineTextByRanges

Combiner

Returns a combiner function that places text values into fixed-width ranges within an output string.

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

Syntax

Combiner.CombineTextByRanges(ranges as list, optional template as nullable text) as function

Parameters

NameTypeRequiredDescription
rangeslistYesA list of two-element lists {offset, length} specifying where and how wide each field is in the output.
templatetextNoAn optional template text used as the base output string. Defaults to a string of spaces.

Return Value

functionA function that accepts a list of text values and fits each into the corresponding {offset, length} range in the output.

Remarks

Combiner.CombineTextByRanges is the inverse of Splitter.SplitTextByRanges. It returns a combiner function that, when called with a list of text values, places each value into the corresponding {offset, length} range in the output string.

Each {offset, length} pair specifies the starting character position and the width of the field. If a value is shorter than the field width, it is right-padded with spaces. If a value is longer than the field width, it is truncated to fit.

The optional template parameter provides the base string; any positions not covered by a range retain the template characters. If no template is provided, the output is filled with spaces.

This function is the structured counterpart of Combiner.CombineTextByPositions — use it when you need both positional and width control over each field.

Examples

Example 1: Place two values into fixed-width fields

Combiner.CombineTextByRanges({{0, 5}, {5, 5}})({"Hello", "World"})
Result
Result
1HelloWorld

Example 2: Values padded to field width

Combiner.CombineTextByRanges({{0, 10}, {10, 10}})({"Alice", "Bob"})
Result
Result
1Alice Bob

Example 3: Values truncated when too long for the field

Combiner.CombineTextByRanges({{0, 3}, {3, 3}})({"Hello", "World"})
Result
Result
1HelWor

Example 4: Use with Table.CombineColumns to produce fixed-width output

Table.CombineColumns(
    #table({"Code", "Name"}, {{"US", "United States"}}),
    {"Code", "Name"},
    Combiner.CombineTextByRanges({{0, 2}, {2, 15}}),
    "Record"
)
Result
Record
1USUnited States

Compatibility

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