Lines.ToText

Lines

Converts a list of text lines into a single text value by joining the lines with line separators.

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

Syntax

Lines.ToText(lines as list, optional quoteStyle as nullable number, optional includeByteOrderMark as nullable logical) as text

Parameters

NameTypeRequiredDescription
lineslistYesA list of text values, each representing one line.
quoteStylenumberNoControls how line endings within quoted fields are treated. Use QuoteStyle.None (default) or QuoteStyle.Csv.
includeByteOrderMarklogicalNoWhen true, prepends a byte order mark to the output. Defaults to false.

Return Value

textA single text value with each element from lines joined by line feed characters.

Remarks

Lines.ToText joins a list of text values into a single multi-line string by inserting a line feed character (#(lf)) between each element. This is the inverse of Lines.FromText, making the two functions natural companions for round-trip text processing: split a text into lines, transform or filter them, then rejoin with Lines.ToText.

The function is most useful when you have manipulated a list of lines and need to produce a single text output — for example, after filtering out blank or comment lines from a source file, reordering lines, or applying transformations to each line.

Unlike Text.Combine, which requires you to explicitly provide a delimiter, Lines.ToText automatically uses the standard line separator. This makes intent clearer when the goal is to reconstruct line-oriented text. Use Text.Combine when you need a custom separator such as a comma or tab. For binary output (e.g., writing to a file or API), use Lines.ToBinary instead.

Examples

Example 1: Join a list of lines into multi-line text

Lines.ToText({"CustomerName,Product", "Alice,Widget A", "Bob,Gadget B"})
Result
Result
1CustomerName,Product Alice,Widget A Bob,Gadget B

Example 2: Filter lines then rejoin

let
    source = "Alice,Widget A#(lf)#(lf)Bob,Gadget B#(lf)#(lf)Charlie,Widget C",
    lines = Lines.FromText(source),
    nonEmpty = List.Select(lines, each _ <> ""),
    result = Lines.ToText(nonEmpty)
in
    result
Applied Steps

The final output — rejoins the non-empty lines into a clean multi-line text value.

Result
1Alice,Widget A Bob,Gadget B Charlie,Widget C

Example 3: Reconstruct a modified text file

let
    lines = {"Alice,Widget A", "Bob,Gadget B", "Charlie,Widget C"},
    transformed = List.Transform(lines, each
        Text.BeforeDelimiter(_, ",") & "," & Text.Upper(Text.AfterDelimiter(_, ","))
    ),
    result = Lines.ToText(transformed)
in
    result
Applied Steps

The final output — joins the transformed lines into a single multi-line text value.

Result
1Alice,WIDGET A Bob,GADGET B Charlie,WIDGET C

Compatibility

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