Updated on

Occurrence.Last (1) is an enumeration that specifies the occurrence of an element in a sequence. It is a member of the Occurrence.Type and indicates the position of the last occurrence of the found value.


Let’s look at an example using the Occurrence.Last enumeration. The List.PositionOf function supports an optional Occurrence Type. You can enter the Occurrence.Last enumeration in the third argument, or write the shorthand value 1.

// Below statements return the index-position 2
= List.PositionOf( { "ape", "duck", "ape", "cow" },  "ape", Occurrence.Last )
= List.PositionOf( { "ape", "duck", "ape", "cow" },  "ape", 1 ) 

The Text.PositionOf function also supports the optional occurrence parameter and shows similar behavior.

// Below statements return the index-position 16
= Text.PositionOf( "We all want pasta", "a", Occurrence.Last ) 
= Text.PositionOf( "We all want pasta", "a", 1 ) 

An example use-case could be this. You have a string that starts with a code and ends with some text. You can find the position of the last number value in the code. Then extract all text up to that point.

= Text.Start(
   "599-44 My Text",
   Text.PositionOfAny( ( "599-44 My Text" ), { "0".."9" }, Occurrence.Last ) +1 )

Other related enumerations are:

Applies to

Here’s a list of functions that work with Occurrence.Type:

BI Gorilla Youtube Channel

Contribute » | Contributors: Rick de Groot