cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jmartin
Level: Powered On

FirstN??

Hi,

 

If I have a column with a sortorder and use the following formula to order.

 

SortByColumns('[dbo].[SurveyQuestions]',"SortOrder")

 

How do I return a record at row 2..3.. etc  

 

Something like 

 

FirstN(SortByColumns('[dbo].[SurveyQuestions]',"SortOrder"), 2).Question

 

 

Thanks

J

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: FirstN??

There's no "indexing" function in PowerApps where you can retrieve a specific record by its position; but you can use a combination of the FirstN and Last functions to accomplish that.

 

In your case, if you want the second item in your (sorted) list of items, you can use the following expression:

 

Last(FirstN(SortByColumns('[dbo].[SurveyQuestions]', "SortOrder"), 2)).Question

Can you explain what is your scenario where you want to retrieve a specific item (by position) of your data source? It would be interesting to know why you need that functionality. Thank you!

View solution in original post

3 REPLIES 3
Community Support Team
Community Support Team

Re: FirstN??

Hi @jmartin,

 

If you would like to return a single record, we could take use of Lookup function.

For Multiple records, function filter, search should be able to deal with that:

Filter, Search, and Lookup functions in PowerApps

 

So here if you would like to show the Question value of the second row from the SQL Table, we could write the formula as below:

 

Lookup(SortByColumns('[dbo].[SurveyQuestions]',"SortOrder"), SortOrder=2).Question

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: FirstN??

There's no "indexing" function in PowerApps where you can retrieve a specific record by its position; but you can use a combination of the FirstN and Last functions to accomplish that.

 

In your case, if you want the second item in your (sorted) list of items, you can use the following expression:

 

Last(FirstN(SortByColumns('[dbo].[SurveyQuestions]', "SortOrder"), 2)).Question

Can you explain what is your scenario where you want to retrieve a specific item (by position) of your data source? It would be interesting to know why you need that functionality. Thank you!

View solution in original post

jmartin
Level: Powered On

Re: FirstN??

Hi @CarlosFigueira,

 

Perfect workaround. I use the indexing to return a specific row for a list of questions in a database. The table has an orderBy column however the values are not sequential.  e.g. 10 , 20 , 30  I presume this is so they can insert more later without requiring multiple updates.

 

Cheers

Jeremy

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,522)