cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper II
Helper II

How can I display top 5 latest items from the SharePoint list with Search functionality?

Hello,

 

I have created PowerApps by connecting existing SharePoint list with 200 items.On Browse Screen, it displays items as per following formula:

 

SortByColumns(Filter([@'DataSource'], StartsWith(Title, TextSearchBox1.Text)), "Title", If(SortDescending1, Descending, Ascending))

 

While, I want to display top 5 latest items from SharePoint list with Search functionality ( Meaning, I should be able to find items from the gallery using keyword), I have tried  with LastN(DataSource,5), however it doesn't display the latest items, also how can I achieve the search functionality? 

 

Is there any restriction in gallery to display top 5 latest items?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Hi @PowerApper25 ,

The LastN filter depends on the Sort, so your current code will show the last 5 sorted by title - try this on ID

LastN(
   Sort(
      Filter(
         [@'DataSource'], 
         StartsWith(
            Title, 
             TextSearchBox1.Text
         )
      ), 
      ID, 
     Descending
   ),5
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

6 REPLIES 6
Super User III
Super User III

Hi @PowerApper25 ,

The LastN filter depends on the Sort, so your current code will show the last 5 sorted by title - try this on ID

LastN(
   Sort(
      Filter(
         [@'DataSource'], 
         StartsWith(
            Title, 
             TextSearchBox1.Text
         )
      ), 
      ID, 
     Descending
   ),5
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Super User III
Super User III

First of all with only 200 items, check your delegation limit if its less than 200 by going to setting ...> Advance setting and can be increased up to 2000. 

 

Secondly, if it still does not work, try collection:
      ClearCollect(MyTable,[@'DataSource'])

Then filter with:

      SortByColumns(Filter(MyTable, StartsWith(Title, TextSearchBox1.Text)),
     "Title", If(SortDescending1, Descending, Ascending))

After that you can filter the last 5:
         LastN(MyTable,5)
Note: You can combine the last two formulas if you want to

 

 

@WarrenBelz 

 

default datarow limit was 500, I have changed as 2000, however formula is not displaying expected results.

 

Formula :

 

 

 

LastN(
   Sort(
      Filter(
         [@'DataSource'], 
         StartsWith(
            Title, 
             TextSearchBox1.Text
         )
      ), 
      ID, 
     Descending
   ),5
)

 

 

Result:

f1.png

 

Formula 2:

 

 

LastN(
   Sort(
      Filter(
         [@'DataSource'], 
         StartsWith(
            Title, 
             TextSearchBox1.Text
         )
      ), 
      ID, 
     Aescending
   ),5
)

 

 

 

Result:

f2.png

 

While Expected Result is:

 

Record - 201

Record - 199

Record - 198

Record - 197

Record - 196

 

What could have gone wrong?

@eka24 

 

Thank you, unfortunately, It was throwing an error while writing formula one by one to combine them, therefore it did not work for me.

Please Can yo display screenshot of the error?

@PowerApper25 

 

try this and tell me if it works

FirstN(
   Sort(
      Filter(
         [@'DataSource'], 
         StartsWith(
            Title, 
             TextSearchBox1.Text
         )
      ), 
      ID, 
     Descending
   ),5
)

 

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 (12,990)