web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

FirstN??

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

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

Categories:
I have the same question (0)
  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    Hi @Anonymous,

     

    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

  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    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!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 305 Most Valuable Professional

#2
11manish Profile Picture

11manish 212

#3
Valantis Profile Picture

Valantis 167

Last 30 days Overall leaderboard