Power Query New Line: How to Insert Line Breaks
In this article
To insert a new line in Power Query, you must use the special character sequence #(lf) for a Line Feed or #(cr)#(lf) for a Carriage Return and Line Feed within a custom column formula. Because Power Query does not allow you to simply press Enter inside the formula bar to create a line break in the data, these special escape sequences are the only way to force text onto a new line for reports or exports. This is essential when you are concatenating multiple columns—such as an address consisting of Street, City, and Zip—and want them to appear stacked rather than in one long string.
What You'll Need
- Microsoft Excel or Power BI Desktop with Power Query installed.
- A dataset containing the text columns you wish to merge or modify.
- Basic familiarity with the "Add Column" tab in the Power Query Editor.
Step-by-Step
- Open your data in the Power Query Editor. If you are in Excel, go to the Data tab and select Get Data or transform an existing table by clicking Transform Data.
- Navigate to the Add Column tab on the top ribbon.
- Select Custom Column from the ribbon. This opens the Custom Column dialog box where you can write your formula.
- In the New column name field, give your column a descriptive name, such as "Formatted Address" or "Combined Notes".
- In the Custom column formula box, start your formula with an equals sign (
=). - Select the first column you want to include by double-clicking it from the available columns list on the right. For example,
[StreetAddress]. - Type the concatenation operator, which is the ampersand (
&). - Type the line break sequence inside double quotes:
"#(lf)". The#symbol tells Power Query that a special character follows, and(lf)stands for Line Feed. - Add another ampersand (
&) to continue the string. - Select the second column from the list, such as .
- Repeat the process for any additional lines:
& "#(lf)" & [State] & "#(lf)" & [ZipCode]. - Click OK to create the column.
- Note that in the Power Query preview window, the text may still appear on one line or show a small space. This is normal; the preview does not always render the line break visually.
- Click File > Close & Apply to load the data into your Excel worksheet or Power BI model.
- Once the data is in the Excel worksheet, select the cells and click Wrap Text on the Home tab. The line breaks will now become visible, pushing the text to new lines within the cell.
Common Mistakes
One of the most frequent errors is forgetting the double quotes around the #(lf) sequence. In Power Query (M language), any literal text must be enclosed in quotes. If you write & #(lf) & without quotes, Power Query will return a syntax error because it thinks you are trying to reference a variable or a function that does not exist.
Another common mistake is using \n or \r. While these are standard newline characters in languages like C#, Java, or Python, Power Query uses the M language, which requires the #( ) notation for special characters. Using \n will simply print the literal characters "\n" into your cell rather than creating a break.
Users often assume the line break is broken because they don't see it in the Power Query Editor. It is a mistake to keep changing the formula when the preview looks flat. The rendering happens at the destination (the spreadsheet or the report visual), not in the transformation engine's preview grid.
Finally, neglecting to enable "Wrap Text" in Excel is a primary source of confusion. Even if the #(lf) code is perfectly implemented, Excel defaults to showing text in a single line unless the Wrap Text property is toggled on for those specific cells.
Tips
If you are dealing with data intended for a Windows-based legacy system, try using "#(cr)#(lf)". This combines a Carriage Return (cr) and a Line Feed (lf). While #(lf) works for most modern applications and Excel, some specific text exports require both characters to recognize a hard return.
To make your formulas cleaner, you can create a "Separator" column first. Create a custom column that contains only "#(lf)". Then, when you merge your other columns, you can simply reference that separator column. This is particularly helpful if you decide later that you want to change the line break to a comma or a semicolon across dozens of different merged columns.
When concatenating, always check for null values. In Power Query, if you concatenate a string with a null value (e.g., [Address] & "#(lf)" & [ApartmentNumber] ), and the Apartment Number is null, the entire result becomes null. To prevent this, use the Text.Combine function. For example: . This function ignores nulls and automatically places the line break between every item in the list.
Troubleshooting
If the line breaks are not appearing in your final output, first check the Wrap Text setting in the Excel Home tab. This is the cause of 90% of "missing" line breaks. If Wrap Text is on and it still isn't working, verify the formula in the Power Query Editor. Ensure there are no spaces inside the quotes—it should be "#(lf)", not " #(lf) ", unless you intentionally want leading/trailing spaces.
If you see the literal text "#(lf)" appearing in your cells, it means you have likely wrapped the sequence in a way that Power Query treats it as a string instead of a special character, or you are using a version of a tool that does not support M-language escape sequences. Ensure you are using the Custom Column dialog and not simply renaming a column.
If your data is being exported to a CSV file and the line breaks are causing the CSV to break into new rows (ruining your table structure), you must wrap the resulting column in double quotes during the export process. Most CSV exporters do this automatically, but if you are using a custom script, ensure the text qualifiers are enabled so the line break stays inside the cell.
Frequently Asked Questions
Can I use a keyboard shortcut to insert a new line in the formula bar?
No, pressing Enter or Shift+Enter in the Power Query formula bar simply confirms the formula or moves the cursor; it does not insert a line break character into the resulting data. You must use #(lf).
What is the difference between #(lf) and #(cr)?
#(lf) is a Line Feed (common in Unix/Linux and modern web standards), while #(cr) is a Carriage Return (older Mac standards). Windows typically uses both together (#(cr)#(lf)). For Excel, #(lf) is usually sufficient.
How do I remove line breaks from a column?
Use the Replace Values feature. Right-click the column, select Replace Values, and in the "Value To Find" box, type #(lf). Leave the "Replace With" box empty or put a space, then click OK.
Does Text.Combine work with line breaks?
Yes, Text.Combine is the most efficient way to handle line breaks. You provide a list of columns in curly brackets { } and specify the line break "#(lf)" as the second argument (the separator).
Will these line breaks work in Power BI visuals?
Yes, but only in visuals that support multi-line text, such as Tables or Matrixes. You may need to enable "Word Wrap" in the formatting pane of the specific visual for the breaks to be visible.