Downloads
Power Query MTextBeginner

Text.EndsWith

Tests whether a text value ends with a given piece of text.

Syntax
Text.EndsWith(text as nullable text, substring as text, optional comparer as nullable function) as nullable logical

Returns: true or false, or null when the input is null.

What it does

Text.EndsWith checks the end of a value. Its most common use is file handling: making sure a folder holds only the CSV or PDF files you expect, or that a statement file name ends in the right extension. Like Text.StartsWith, it is case sensitive unless you pass Comparer.OrdinalIgnoreCase.

Syntax and arguments

Example

A bank portal exports statements as files, and some arrive as ".CSV" and some as ".csv". The import step only wants the CSV files, so it keeps every name that ends in the extension whatever the capitals.

let
    Files = #table(type table [FileName = text],
        {{"stmt_2026_09.csv"}, {"stmt_2026_09.CSV"}, {"stmt_2026_09.pdf"}}),
    CsvOnly = Table.SelectRows(Files,
        each Text.EndsWith([FileName], ".csv", Comparer.OrdinalIgnoreCase))
in
    CsvOnly

The result keeps the two CSV rows and drops the PDF. Without the comparer, the ".CSV" file would be dropped by mistake.

Example: a second, different use

Find invoice numbers that end in a "-R" revision suffix so the team can check that each revision replaced the original.

Things to watch

In business terms

Month-end imports depend on picking the right files from a folder: the bank CSV, the payroll PDF and the revision of an invoice. A reliable end test stops the wrong file from being loaded into the close.

Related functions

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