Downloads
Power Query MTextBeginner

Text.End

Returns the last characters of a text value.

Syntax
Text.End(text as nullable text, count as number) as nullable text

Returns: The last count characters, or the whole text if it is shorter, or null when the input is null.

What it does

Text.End takes the last characters of a value. It is the M version of RIGHT. Finance teams use it for the last four digits of a card or bank account, for a check digit at the end of a reference, or for the suffix that marks a revision or a version.

Syntax and arguments

Example

A bank feed holds full account numbers, but the report should show only the last four digits to keep the numbers out of view.

let
    Accounts = #table(type table [Bank = text, Account = text],
        {{"Harbor Bank", "0045129986"}, {"Northwind Credit", "7788213"}}),
    Masked = Table.AddColumn(Accounts, "Last4", each Text.End([Account], 4), type text)
in
    Masked

The Last4 column is "9986" and "8213". The full number is still in the source table, so use this column for the display and keep the full value only where a match needs it.

Example: a second, different use

Take the last two characters of a document reference to read a revision code such as "-A" or "-B" that the ERP appends.

Things to watch

In business terms

Last four digits are how bank accounts, cards and checks are identified on statements and approvals. Showing only the last four keeps a report useful without spreading full account numbers around the team.

Related functions

All Power Query M functions · View as Markdown · M basics