cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rethc
Frequent Visitor

Gallery datasource using a lot of resources

Hi, im working on a simple parcel tracker app that allows users to record parcel tracking info to a sharepoint list. I'd like to add Gallery that displays the last 3 items scanned in the session so the user can see if they were scanned in correctly. I have done this by using FirstN/LastN and SortColumns. However the issue is that it's using a lot of resoruces as its returning the whole sharepoint list (1.3mb). I'm wondering if there was a better way to do this with variables?

 

Gallery - Items property:

FirstN(SortByColumns(DataSource, "ID", Descending), 3)

OR

SortByColumns(LastN(DataSource, 3), "ID", Descending)

rethc_0-1632726938865.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
C-Papa
Super User
Super User

You could put a filter in as well to limit the results, for example, if you know that you will have items scanned every day you could set the create date to more than yesterday, this will limit the result to last last 24 hours and then return the last 3. 

 

FirstN(SortByColumns(Filter(DataSource,Created > DateAdd(Today(),-1,Days)), "ID", Descending), 3)

 

 

View solution in original post

6 REPLIES 6
WarrenBelz
Super User
Super User

Hi @rethc ,

This is really the same thing, but see how it goes for performance

With(
   {
      wList:
      Sort(
         DataSource,
         ID,
         Descending
      )
   },
   FirstN(wList,3)
)

 

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.

C-Papa
Super User
Super User

You could put a filter in as well to limit the results, for example, if you know that you will have items scanned every day you could set the create date to more than yesterday, this will limit the result to last last 24 hours and then return the last 3. 

 

FirstN(SortByColumns(Filter(DataSource,Created > DateAdd(Today(),-1,Days)), "ID", Descending), 3)

 

 

rethc
Frequent Visitor

Genius!! Thank you - it has drastically dropped the resources to around 5842 bytes.

 

I've also noticed that a Gallery in another screen is refreshing after a new record is added. How prevent it from refreshing the Datasource when the screen is not active? I have tried setting the visible property to false but it has made no difference.

rethc_1-1632733447623.png

 

Gallery1 - Items property:

 

 

Filter(DataSource, StartsWith(Title, text_searchbox.Text))

 

 

 

 

C-Papa
Super User
Super User

Sorry, i can't understand what you are asking, maybe re read your question and ask it again. The gallery will refresh when a item is edited or added within the app. The only way to stop this is using collections.

rethc
Frequent Visitor

Hi C-Papa, i want to prevent a gallery in another screen from refreshing.  The default value in my text_searchbox is "" which will bring up all records from the sharepoint site based on my Filter.

 

Is it possible to put an If statement in the Gallery Item property so that if the textbox value is null then do nothing.

 

If(text_searchbox.Text="",
   Filter(DataSource, StartsWith(Title, text_searchbox.Text)),
   Blank()
);

 

 

 

C-Papa
Super User
Super User

What you are trying to achieve is not possible without a collection. the below video should help you out.

 

Working with a PowerApps Collection - YouTube

 

Remember to mark the above answer as a solution to allow others to search and find the correct answer

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,306)