Smart Systems for Home

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

Power Query Right Function: Extract Text From the End

· 6 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

Power Query's Text.End function is the “right” function: it returns a chosen number of characters from the end of a text value. Syntax: Text.End(text as nullable text, count as number) as nullable text. So Text.End("INV-2026-00418", 5) returns 00418, and Text.End("INV-2026-00418", 9) returns 2026-00418. You add it as a custom column in Power Query Editor, or call it from a blank query in the formula bar. There is no separate RIGHT keyword in Power Query; RIGHT belongs to DAX and Excel, and Text.End is the M equivalent.

What You'll Need

  • Excel for Microsoft 365 (or Excel 2021/2024) with Power Query, or Power BI Desktop, or Power Query in Power Apps and Dynamics 365. The steps below use Excel and Power BI wording; menu labels can differ slightly by version, device or region.
  • A table or range loaded, or the Power Query Editor already open on a query.
  • A column of text values, and a clear idea of how many characters you need from the right end. If the length varies per row, you will need a delimiter-based approach instead of a fixed count — see the worked example in Step 5.

Step-by-Step

  1. Load your data into Power Query. In Excel, select any cell in your table and go to Data > From Table/Range. In Power BI Desktop, use Home > Transform data to open the Power Query Editor on an existing query. Confirm the column you want is typed as Text (the column header shows an “ABC” icon). If it shows “123”, click the icon and choose Text first — otherwise the function will error on numbers.
  2. Add a custom column. On the Add Column tab (not Transform, which overwrites the original), click Custom Column. In Power BI the button sits on the Add Column ribbon group; in Excel it is also under Add Column > Custom Column. Give it a name such as Suffix.
  3. Write the formula. In the formula box type: Text.End([InvoiceNumber], 5) Replace [InvoiceNumber] with your actual column name — Power Query is case-sensitive about column names, and the square brackets are required. A single value like "2026-00418" needs double quotes; a column reference does not.
  4. Check the results before clicking OK. The dialog shows a preview message such as “No syntax errors have been detected”. That only proves the syntax parses, not that the logic is right — close the dialog with OK and scroll the new column to eyeball several rows, especially the shortest and longest values.
  5. Handle variable-length text with a delimiter instead. A fixed count fails when values differ in length. If every code ends with something like a dash and four digits (ABC-1234, XY-9876), extract from the right using Text.AfterDelimiter([Code], "-", 1), or combine both: Text.End([Code], 4). For a “last segment after the final delimiter” pattern regardless of length, use Text.AfterDelimiter([Code], "-", {0, RelativePosition.FromEnd}). Power Query counts delimiters from the left by default, so the RelativePosition argument is what makes it count from the right.
  6. Guard against nulls and short strings. Text.End(null, 5) returns null, which is usually fine. But Text.End("AB", 5) returns the whole string "AB" rather than an error — Power Query does not fail when the count exceeds the length, it just returns everything. If you need a clean flag, wrap it: if Text.Length([Code]) >= 5 then Text.End([Code], 5) else null.
  7. Set the right data type. The custom column is text. If the result is numeric (a year, a serial, a last-four digits field you plan to compare), right-click the column header and choose Change Type > Whole Number. Do that after the extraction, never before.
  8. Close and load. Use Home > Close & Load in Excel, or Home > Close & Apply in Power BI. The new column appears in your table, and it refreshes with the source data because the step is recorded in the query, not typed into cells.

Common Mistakes

  • Using RIGHT instead of Text.End. RIGHT() is a DAX and worksheet function. In a Power Query custom column it produces an error like “The name 'RIGHT' wasn't recognized.” Use Text.End.
  • Adding the step in the wrong place. Creating the column under Transform overwrites the source column. Use Add Column so the original stays available for other extractions.
  • Forgetting brackets or quotes. Text.End(InvoiceNumber, 5) without brackets is read as a function call on an unknown name. Column references are always [Column].
  • Applying a fixed count to variable-length data. Last-five characters of “ABC-1234” gives “-1234”; on “A-56” it gives “A-56”. If the underlying codes vary, a right-length extraction silently returns the wrong slice instead of failing.
  • Running it on numbers. If the column is typed as a number, the function errors. Convert the column to Text first, extract, then optionally convert back.
  • Ignoring leading zeros. Extracting “00418” and then converting to Whole Number turns it into 418. If the zeros matter, keep the column as Text.

Tips

  • Combine with Text.Length when the count depends on the row: Text.End([Code], Text.Length([Code]) - 3) drops the first three characters.
  • Use Text.Range([Code], Text.Length([Code]) - 5, 5) when you need a fixed-length slice starting from the right but with explicit bounds.
  • The equivalent of LEFT is Text.Start; Text.Middle maps to MID. Learning the trio covers almost every text-extraction task.
  • Name the custom column something meaningful, not “Custom”, so later steps and other users can read the query logic.
  • Test a duplicate value deliberately: add a row containing an empty string and a null to see how your formula behaves before it reaches hundreds of thousands of rows.
  • If you extract the same suffix repeatedly across queries, put the logic in a small function query and invoke it, rather than retyping the formula.

Troubleshooting

“The name 'Text.End' wasn't recognized.” Usually a typo — the function is Text.End, not Text.Right or TextEnd. Check capitalisation too.

“We cannot apply operator & to types Text and Number.” You are concatenating a text value with a number somewhere in the formula. Convert the number with Text.From(...).

Every row returns the whole value. The count is larger than the string length, or you referenced the wrong column. Check the count and the exact column name.

The column shows errors on some rows only. Those rows likely contain nulls or non-text values. Expand the error cell to read the message; a null input returns null by design, but a number input errors. Convert the column type to Text and refresh.

Results changed after you hit Close & Load. A downstream step (often an automatic “Changed Type” step added at the end) may convert the column back to a number. Open the query and look at the last step in the Applied Steps list; delete or edit the automatic type step if it undoes your work.

If that did not work, rebuild the step in isolation: create a blank query, type Text.End("ABCDEF", 2) in the formula bar, and confirm it returns “EF”. If that works, the problem is the column reference or type, not the function.

Frequently Asked Questions

Is Text.End the same as RIGHT in Excel?

Functionally yes — it returns the tail of a string. But RIGHT is an Excel worksheet and DAX function, while Text.End is the Power Query (M) function and is case-sensitive.

Does Text.End fail if the count is bigger than the text?

No. It returns the entire string instead of an error, so a wrong count can pass silently. Validate with Text.Length or inspect the shortest values.

How do I take the last characters after a separator?

Use Text.AfterDelimiter with RelativePosition.FromEnd, or split the column by delimiter and expand the last segment.

Can I extract the right characters of a date?

Only if it is stored as text. Convert the date column to Text first, or extract the year directly with .

Why does my new column disappear on refresh?

It does not if it was created in the query. If a column vanishes, a later change to the source (renamed or removed columns) broke the step — check the Applied Steps list for the step showing an error.