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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (17,192)