OpenBI Docs Buy

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
ParameterTypeDescription
texttextThe text to search.
substringtextThe piece to look for.
occurrencenullable number
optional
Occurrence.First (the default), Occurrence.Last or Occurrence.All.
comparernullable 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

Text.Contains, Text.AfterDelimiter, Text.Range.

Last updated · OpenBI Studio 0.3.79