web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Find Element in Array ...
Power Apps
Answered

Find Element in Array and get Position ID

(0) ShareShare
ReportReport
Posted on by 63

Hello, community,

 

in Power Automate, I'm looking for a simple way to find a word (or element in general) in my array and get its position ID. 

 

So let's say, I have this array:

 

[

  "A",

  "B",

  "C",

  "D",

  "E"

]

 

I want to search for "C" and get its position ID, so "2". Is there a simple way to achieve that?

 

 

Best regards,

Dog

Categories:
I have the same question (0)
  • HenriDesmet59 Profile Picture
    295 on at

    Hello,

     

    A way to achieve that is to use a temp collection "CountCollection" :

     

    HenriDesmet59_0-1646747150869.png

    ClearCollect(CountCollection;{Count:true;Value: 0});;
    
    ForAll(
     test_col;
     If(
     Last(CountCollection).Count;
     If(
     ThisRecord.Value = "C";
     Collect(CountCollection;{Count: false;Value: Last(CountCollection).Value + 1});
     Collect(CountCollection;{Count: true;Value: Last(CountCollection).Value + 1})
     )
     )
    )
    
    
    //then use Last(CountCollection).Value to get the index 

    We will put in it a column "Count" to true at the start, and a field "Value" to count the iteration. 

    Inside the ForAll, If the record is not the element we need to find, we add an entry in our "CountCollection" with the column "count" to true and "Value" to last Value + 1.

     

    When we find the element, we collect a last entry in "CountCollection" with "count". 

    With the "If condition" at the start of the ForAll, Once the last entry of the "CountCollection" count column is set to false they will be no more entry.

     

    At the end to get the index you can take the value of the last element of the "CountCollection".7

     

    (Sorry I'm french and maybe my english is not that good, and take care to replace ";" by "," in the code) 

     

  • DogWithRedSocks Profile Picture
    63 on at

    Hi HenriDesmet59, thank you for your answer, I appreciate your help!

     

    From what I see, you're using your solution in CanvasApps, whereas I need a solution in Power Automate 🙂

     

    However, in the meantime, I found a workaround. I'm using a Apply to Each action on the array output, using two conditions to look for my words, using three Integer variables (StartID, EndID, RunningID), and incrementing the RunningID by 1 for every element in the array. Once I stumble upon the word in the array, I write the value from RunningID to my StartID variable and EndID variable.

  • HenriDesmet59 Profile Picture
    295 on at

    aaah I'm sorry, didn't saw It was for PowerAutomate ! Yes an apply to each is a good way to get the Index of the Element ! Cool !

  • v-yujincui-msft Profile Picture
    Microsoft Employee on at

    Hi @DogWithRedSocks ,


    Glad to see you solved the problem.
    You could mark your answer as a 'solution' to close the case.

     

    In addition, it's easier to get more assistance by posting in the corresponding forum.

    https://powerusers.microsoft.com/t5/Microsoft-Power-Automate/ct-p/MPACommunity

     

     

    Best Regards,
    Charlie Choi

     

  • Verified answer
    DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi all,

     

    I saw this problem being referenced on Reddit and thought I could provide you with a solution.  I've started with the array, followed by a select that uses range starting at 0, using length of the array for the number of values, 0,1,2,3,4.  Note that the index for an array starts at 0.  I create a string key based on the position from range outputs('compose')?[item()] and position based on the range item(). 

     

    DamoBird365_0-1658343101981.png

    This is what the flow run for select creates:

    DamoBird365_3-1658343733853.png

     

    Using filter array, I can search for the string value "Pie" based on equalling item()['String'] i.e. the key created in the select. This will return one object in the array and by using first, we can return the position first(body('Filter_array'))?['Position']

     

    DamoBird365_1-1658343317028.png

    The result is position 4 (as indexes run 0,1,2,3,4).  

    DamoBird365_2-1658343460590.png


    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts. Thanks

     

     

  • JayaBothra Profile Picture
    2 on at

    Hi, Can you please share the snippet of the flow with me. I have a similiar situation and stuck since long

  • Aolo Profile Picture
    3 on at

    It worked for me
    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,074

#2
Valantis Profile Picture

Valantis 639

#3
11manish Profile Picture

11manish 606

Last 30 days Overall leaderboard