How to find the Index() position of an item from a list

Sometimes when working with lists, you find yourself needing to know at what position an item sits in a list.

  • Is it the first thing? The last thing?
    • At what point does this item sit in a list? Is it number 5 in the list? Number 25?

Iโ€™ve put together a sample app that demonstrates how to find such things:


The real magic is with the following formula (which Iโ€™ve cleaned so itโ€™s โ€œuniversalโ€)

count(
 split(
   left(
 concatenate(ENTER_LIST_HERE),
 find(
   WHAT_TO_FIND,
concatenate(ENTER_LIST_HERE)
 ) + (LEN(WHAT_TO_FIND) - 1)
),
 " , ")
)

Replace the placeholders with the appropriate data:

  • ENTER_LIST_HERE should be the list you need to use
    • this could be an EnumList [column] or list virtual column
    • this could be a table[Column] result
    • this could be a SELECT() result
    • any list of values is appropriate here
  • WHAT_TO_FIND
    • This is the data-value that you wish to find the index position for
      • this could be a [column] value
      • this could be a โ€œhard-coded valueโ€
      • this could be the result of a formula
        • If youโ€™re working with a non-text value, youโ€™ll need to convert the data into a text in order for things to work - the sample app contains specifics and examples.

20 8 4,051
8 REPLIES 8

Other posts from the community that literally answer the same thing, but that didnโ€™t pop up when I was making my post - and people canโ€™t seem to find when asking a question with the keywords:

โ€œlistโ€
โ€œindexโ€
โ€œpositionโ€


Maybe people will be able to find the answer now???

Now THAT is an expression. Bookmarking it for later, thanks Matt !

3X_b_8_b831944e5f1570abd590d5e24849cb16b44cc603.jpeg

3X_5_6_5656eaa26cf371ad7561ec267f7d1fc31aaff0e7.gif

3X_4_e_4e2301c49a35650a196b9bd1d2153da0d726b8f8.gif

Such a juicy expression

Just a note on this tip.... If the value is not in the list it will return position 1. You may want to start with something like IFS(IN(xxx,list),expressionabove) to improve this excellent tip

Very creative ! I had not notice that we can have any type as CONCATENATE's argument, even been clear in the function documentation:

 

RBTAndrade_0-1644066840688.png

 

And, for anyone who lands here seeking a streamlined way to identify the index (position) of a row among multiple rows, here's the technique I'm using--fortunately much more straightforward find the index of an item within a list.

COUNT(SELECT(Table/SliceName[AnyColumnName], [_RowNumber] <= [_THISROW].[_RowNumber]))

If you can depend on the group of rows being contiguous in the table's data source, here's an even simpler version:

[_RowNumber] - MIN(Table/SliceName[_RowNumber]) + 1 

 

Top Labels in this Space