# Power Automate: Check if Text Starts or Ends With

> For the full documentation index, see https://250highstreet.com/llms.txt

> Use startsWith() and endsWith() in Power Automate to test the start or end of text. Case rules, file extension checks, Condition setup and indexOf().

Use startsWith(text, 'value') to test the start of text and endsWith(text, 'value') to test the end. Both return true or false, and neither one cares about upper or lower case.

## What is the syntax of startsWith() and endsWith()?

Each function takes two text values: the text to check, then the text to look for. startsWith('INV-2026-014', 'INV-') returns true. endsWith('report.pdf', '.pdf') returns true.

Add the expression in a Compose action or in the advanced mode of a Condition. To check a column, write startsWith(triggerOutputs()?\['body/Title'\], 'INV-').

## Is startsWith() case-sensitive?

No. startsWith('invoice 12', 'INVOICE') returns true. endsWith() works the same way.

Microsoft documents no exact-case version. contains() is case-sensitive, so contains(substring(variables('text'), 0, 4), 'INV-') checks the first four characters with case. The text must be at least four characters long. See [extract text with substring](/guides/power-automate-substring-extract-text/) for the slice syntax.

## How do you check a file extension?

Use endsWith() on the file name: endsWith(triggerOutputs()?\['body/{Name}'\], '.xlsx'). The check passes for .XLSX as well, because the match ignores case.

Put the expression in a Condition before the step that handles the file. Send the No branch to a Terminate action or skip it.

## How do you find where a value appears inside text?

Use indexOf(). indexOf('order-4471-final', '4471') returns 6. The count starts at 0. When the value is not in the text, the result is -1.

lastIndexOf() returns the last position instead of the first. A result of 0 from indexOf() means the text starts with the value. A result of -1 means it does not appear at all.

## When should you use contains() instead?

Use [contains()](/guides/power-automate-contains-function-text-array/) when the value can sit anywhere in the text. Use startsWith() or endsWith() when the position matters, such as a prefix on an ID or an extension on a file.

A prefix check is stricter. contains('CREDIT-INV-9', 'INV-') returns true, but startsWith('CREDIT-INV-9', 'INV-') returns false.

## Why does the check fail on text with extra spaces?

A leading space breaks startsWith(). startsWith(' INV-12', 'INV-') returns false. A trailing space breaks endsWith() in the same way.

Remove the spaces first: startsWith(trim(variables('text')), 'INV-'). See [trim spaces from text](/guides/power-automate-trim-remove-spaces-from-text/). If the value can be null, wrap it with coalesce(value, '') so the function gets text.

## Can you use startsWith in a Get items filter query?

Yes. SharePoint accepts startswith(Title,'INV-') in the Filter Query box of Get items. The server filters the rows before the flow gets them.

Use the filter only for startswith. For an end-of-text test, get the items and then use a Filter array action with endsWith(). If a query returns nothing, see [filter query not working](/guides/power-automate-get-items-filter-query-not-working/).

## FAQ

### Does startsWith() work on numbers?

Not directly. Convert the number to text first with string(). For example, startsWith(string(12345), '12') returns true.

### What does startsWith() return for empty text?

It returns false unless the search value is also empty. Test for an empty value first if blank rows are possible.

### Can I check several prefixes at once?

Yes. Join the checks with or(): or(startsWith(text, 'INV-'), startsWith(text, 'CR-')). The result is true when either one matches.

## Sources

- [Reference guide to workflow expression functions in Azure Logic Apps and Power Automate](https://learn.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference)
- [Power Automate: startsWith function](https://manueltgomes.com/reference/powerautomate-function-reference/startswith-function/)

## Related guides

- [Power Automate substring(): Get Part of a Text Value](/guides/power-automate-substring-extract-text/)
- [Power Automate contains(): Check Text or a List for a Value](/guides/power-automate-contains-function-text-array/)
- [Power Automate trim(): Remove Spaces From Text](/guides/power-automate-trim-remove-spaces-from-text/)
- [Power Automate Get items filter query returns nothing: how to fix it](/guides/power-automate-get-items-filter-query-not-working/)

Source: https://250highstreet.com/guides/power-automate-startswith-endswith-check-text/
