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

Re: Retrieve index of first matching record in table

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
Highlighted
Community Support
Community Support

Re: Retrieve index of first matching record in table

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

Highlighted
Helper I
Helper I

Re: Retrieve index of first matching record in table

Hi @v-bofeng-msft ,

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

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (4,449)