Text.PositionOf
Where a piece of text is found in a text, counted from 0: the first place, the last, or every place.
Group: Text and characters. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Text.PositionOf(text as text, substring as text, optional occurrence as nullable number, optional comparer as nullable function) as any
| Parameter | Type | Description |
|---|---|---|
text | text | The text to search. |
substring | text | The piece to look for. |
occurrence | nullable number optional | Occurrence.First (the default), Occurrence.Last or Occurrence.All. |
comparer | nullable function optional | How to compare: Comparer.Ordinal (the default, case counts) or Comparer.OrdinalIgnoreCase. |
Returns
any. A position from 0, -1 when the piece isn't found, or a list of positions with Occurrence.All.
Examples
The first place
Text.PositionOf("Oslo-Bergen-Oslo", "Oslo")
0
Every place
Text.PositionOf("Oslo-Bergen-Oslo", "Oslo", Occurrence.All)
{0, 12}
Not found
Text.PositionOf("Oslo-Bergen-Oslo", "Tromsø")
-1