cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,637)