cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Adrian2
Helper I
Helper I

Retrieve index of first matching record in table

Hi , I am trying to find the index of the first matching record in a table.

 

So for this table,

Apple
Orange
Pear
Grape
Melon

 

I would like to search for "Pear" and get the record index which is 3. How can this be done? The functions such as Find(), LookUp() etc. return the record but not the record index.

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @Adrian2 :

If your data source itself does not have an index, I suggest you use the ForAll function.I've made a test for your reference:

My data source:

ClearCollect(YourTable,["Apple","Orange","Pear""Grape","Melon"])

1\Add a text input control-TextInput3

2\Add a button and set it's OnSelect property to:

Clear(Result); /*Result is my custom collection*/
ForAll(
    YourTable,
    Collect(
        Result,
        {
            No: CountRows(Result) + 1, /*Create a serial number for each record*/
            Value: Value
        }
    )
);

Select the button

3\Add a label control and set it's Text property to:

LookUp(Result,Value=TextInput3.Text).No

This is the serial number of the first searched record.

18.gif

Best Regards,

Bof

View solution in original post

2 REPLIES 2
v-bofeng-msft
Community Support
Community Support

Hi @Adrian2 :

If your data source itself does not have an index, I suggest you use the ForAll function.I've made a test for your reference:

My data source:

ClearCollect(YourTable,["Apple","Orange","Pear""Grape","Melon"])

1\Add a text input control-TextInput3

2\Add a button and set it's OnSelect property to:

Clear(Result); /*Result is my custom collection*/
ForAll(
    YourTable,
    Collect(
        Result,
        {
            No: CountRows(Result) + 1, /*Create a serial number for each record*/
            Value: Value
        }
    )
);

Select the button

3\Add a label control and set it's Text property to:

LookUp(Result,Value=TextInput3.Text).No

This is the serial number of the first searched record.

18.gif

Best Regards,

Bof

View solution in original post

Hi @v-bofeng-msft ,

Thank you very much for the detailed solution! It is exactly what I was looking for. 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,793)