Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power Query Lines.FromText: A Step-by-Step Guide

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The Lines.FromText function in Power Query converts a single text value into a list of text lines, splitting on line breaks (carriage return, line feed, or both). It is the quickest way to turn a multi-line block of text—such as a CSV file loaded as one string, a log file, or pasted content—into rows you can further transform. You do not need any special setup beyond a Power Query editor (in Excel, Power BI, or another host); the function is built into the M language.

What You'll Need

  • A Power Query editor open in Excel, Power BI Desktop, or another tool that supports M (the steps below use the Power Query Editor interface; menu labels may vary slightly by version and host).
  • A text value to split—either from a file, a cell, or a manually entered string.
  • Basic familiarity with adding a custom column or writing a small M expression.

Step-by-Step

  1. Load your text into Power Query. If your text is in a file (e.g., a .txt or .csv), use Data > Get Data > From File > From Text/CSV (or the equivalent in your host). If the text is in a single cell, you can reference that cell via Data > From Table/Range after formatting the cell as a table. The goal is to have a query step that returns the text as a single value—often a one-cell table or a scalar.
  2. Open the Advanced Editor or add a custom step. For a quick test, go to Home > Advanced Editor and inspect the current query. Alternatively, right-click a query step and choose Insert Step After to add a new step where you can write an expression. (If you prefer a formula bar, enable it via View > Formula Bar.)
  3. Write the Lines.FromText expression. The syntax is Lines.FromText(text as text, optional quoteStyle as nullable number) as list. In its simplest form, replace the previous step reference with Lines.FromText(PreviousStepName). For example, if your previous step is called Source and it returns a text value, use:
    = Lines.FromText(Source)
    If your text is in a table column, first extract the value (e.g., Source{0}[Column1]) before passing it.
  4. Convert the resulting list to a table. After the step, you will see a list of text values. To turn it into rows, click List Tools > Transform > To Table (or use Convert > To Table from the ribbon). In the dialog, leave the default delimiter or choose none; the list items become rows in a single column.
  5. Rename and continue transforming. Rename the column to something meaningful, then apply further steps such as splitting by delimiter, trimming, or filtering. For example, if each line is a CSV record, use Split Column > By Delimiter on the comma.
  6. Handle optional quote styles if needed. The second argument, quoteStyle, controls how quoted fields are treated. Use QuoteStyle.Csv (a built-in constant) if your lines contain quoted text with embedded line breaks that should be preserved as part of a single field. Without it, every line break is treated as a row separator. For most plain-text splitting, omit the argument.
  7. Close and load. Once the data looks correct, click Close & Load (or Close & Load To...) to send the result to a worksheet or data model.

Common Mistakes

  • Passing a table instead of text. Lines.FromText expects a text scalar, not a table or column. Extract the single value first (e.g., MyTable{0}[Column1]).
  • Forgetting to convert the list to a table. The function returns a list; if you try to load it directly, Power Query may show a list of values in one cell. Use To Table to get proper rows.
  • Ignoring quote styles. If your text contains quoted fields with line breaks inside quotes, omitting QuoteStyle.Csv will split those fields incorrectly.
  • Assuming it parses CSV. Lines.FromText only splits on line breaks; it does not handle delimiters or headers. You still need to split columns afterwards.
  • Using it on a column directly. If you add a custom column with Lines.FromText([Column]), each row returns a list, which may not be what you want. Use it on a single text value, then expand.

Tips

  • Use Lines.FromText together with Text.Combine if you need to rejoin lines later.
  • To test quickly, create a blank query and enter = Lines.FromText("Line1#(lf)Line2") in the formula bar; the result is a list of two items.
  • If your source uses only carriage returns (old Mac style), the function still splits correctly because it recognizes CR, LF, and CRLF.
  • For very large text files, consider using From Text/CSV with the appropriate delimiter instead of loading the whole file as one string; it is more memory-efficient.
  • Remember that the function is case-sensitive: Lines.FromText, not lines.fromtext.

Troubleshooting

  • Error: “We cannot convert a value of type Table to type Text.” You passed a table. Reference a single cell or use Table.FirstValue to extract the text.
  • The result is a list of one item containing the whole text. Your text may not contain line breaks, or the line breaks are non-standard (e.g., Unicode line separator). Check the source; you may need to replace unusual characters with #(lf) first.
  • Quoted fields are split incorrectly. Add QuoteStyle.Csv as the second argument: Lines.FromText(Source, QuoteStyle.Csv).
  • List items appear as “Error” or “null”. Ensure the input is a valid text value; null input returns null. Use Text.From to convert numbers or other types.
  • The step is not available in the ribbon. Lines.FromText is an M function, not a button. You must write it in the formula bar or Advanced Editor.

Frequently Asked Questions

What does Lines.FromText actually return?

It returns a list of text values, where each item is one line from the input text, with line break characters removed.

Can I use Lines.FromText on a column of text values?

Not directly. It expects a single text scalar. To apply it per row, add a custom column with Lines.FromText([YourColumn]), then expand the resulting lists.

Does it handle CSV files with quoted line breaks?

Yes, if you pass QuoteStyle.Csv as the second argument. Without it, every line break is treated as a row separator, even inside quotes.

Is Lines.FromText available in Excel and Power BI?

Yes, it is part of the standard M library in both Excel Power Query and Power BI Desktop, as well as other hosts that use Power Query.

How do I split text that uses only carriage returns?

The function automatically recognizes CR, LF, and CRLF as line breaks, so no extra steps are needed.

Can I reverse the operation?

Yes, use Text.Combine on the list, optionally with a delimiter such as #(lf), to join lines back into a single text value.