Text.EndsWith
Tests whether a text value ends with a given piece of text.
Text.EndsWith(text as nullable text, substring as text, optional comparer as nullable function) as nullable logicalReturns: 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
- text: the value to test.
- substring: the text the value must end with.
- comparer (optional): Comparer.OrdinalIgnoreCase makes the test ignore case. Leave it out for an exact match.
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
- It is case sensitive by default, which is the usual reason a file is missed.
- Null in gives null out, and Table.SelectRows drops rows where the test is null.
- It only looks at the end, so "statement.csv.bak" does not end in ".csv".
- For a real file type check, look at the file's contents as well as its name.
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.