Lines.FromText

Updated on

Lines.FromText is a Power Query M function that converts a text value to a list of text values split at line breaks. The function returns a list of text values with or without line break characters based on the includeLineSeparators parameter.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Lines.FromText(
   text as text,
   optional quoteStyle as nullable number,
   optional includeLineSeparators as nullable logical,
) as list
ArgumentAttributeDescription
TextThis is the text value to convert.
quoteStyleOptionalYou can provide a QuoteStyle Type that instructs how to deal with double quote characters. You can choose from QuoteStyle.None or QuoteStyle.Csv.
includeLineSeparatorsOptionalInstructs Power Query whether to return line separators in the result. You can either provide the value true or false. Power Query defaults to false when omitting this argument.

Description

Converts a text value to a list of text values split at lines breaks. If includeLineSeparators is true, then the line break characters are included in the text.

Examples

The Lines.FromText function splits a text value by line feed, also known as line separator.

// Returns { "a", "b", "c", "d" }
= Lines.FromText( 
"a
b
c
d"
)

// This is identical to: 
= Lines.FromText( "a#(lf)b#(lf)c#(lf)d" )

You can provide a QuoteStyle Type to indicate how to interpret double quotes in a string. You can choose from QuoteStyle.None or QuoteStyle.Csv.

// Results in a single item in a list, including a linebreak
// Returns: { "This is a ""string,#(lf)string""" }

= Lines.FromText( 
    "This is a ""string, 
in quotes""", 
     QuoteStyle.Csv  )

// Results in a 2 items list
// Returns: { "This is a ""string,", "string""" }
= Lines.FromText( 
    "This is a ""string, 
in quotes""", 
     QuoteStyle.None  )
Lines.FromText behavior towards quotes with QuoteStyle Type

The includeLineSeparators argument instructs Power Query whether to return line separators in the result. Specifying true will return line separators, represented by #(lf). When providing false (or omitting the argument), the line-separators are used to split the string but are not returned in the result. Have a look at the following example:

// Returns { "a#(lf)", "b#(lf)", "c#(lf)", "d#(lf)" }
= Lines.FromText( 
    "a#(lf)b#(lf)c#(lf)d", 
    QuoteStyle.Csv, 
    true 
)

// Returns { "a", "b", "c", "d" }
= Lines.FromText( 
    "a#(lf)b#(lf)c#(lf)d#(lf)", 
    QuoteStyle.Csv, 
    false
)
Lines.FromText behavior with line separators

Other functions related to Lines.FromText are:

BI Gorilla Blog

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/lines-fromtext