cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
OsmandFernando
Post Prodigy
Post Prodigy

How to show the last item at top in a gallery

Hi, 

 

I do not have the sort option in the gallery, as I purposefully removed it. I have the following formula in the Items property of the Gallery, 

 

If(IsBlank(TextSearchBox1),'Item Master',Search(AddColumns('Item Master',"Model",'Model Number'),TextSearchBox1.Text,"Model","ItemName"))

 

I want to show the last item at top in the gallery like descending. 

 

How can I do that?

 

Osmand 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@OsmandFernando 

Please forgive me for asking: but why can you not use the SORT function?  I would like to understand your requirement.

 

Sort(
    If(IsBlank(TextSearchBox1),'Item Master',Search(AddColumns('Item Master',"Model",'Model 
    Number'),TextSearchBox1.Text,"Model","ItemName")),
    ID, Descending
)

 

Note: my code above assumes the records were initially sorted by ID: 1, 2, 3, 4, 5...

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

5 REPLIES 5
mdevaney
Super User
Super User

@OsmandFernando 

I want to make sure I understand your request.

 

Let's say you have a Gallery that looks like this:

  • Record 1
  • Record 2
  • Record 3
  • Record 4
  • Record 5

 

Do I understand correctly that the solution should look like this?

  • Record 5
  • Record 1
  • Record 2
  • Record 3
  • Record 4

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

No dear @mdevaney should be like as follows

 

  • Record 5
  • Record 4
  • Record 3
  • Record 2
  • Record 1

Osmand

@OsmandFernando 

Please forgive me for asking: but why can you not use the SORT function?  I would like to understand your requirement.

 

Sort(
    If(IsBlank(TextSearchBox1),'Item Master',Search(AddColumns('Item Master',"Model",'Model 
    Number'),TextSearchBox1.Text,"Model","ItemName")),
    ID, Descending
)

 

Note: my code above assumes the records were initially sorted by ID: 1, 2, 3, 4, 5...

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

v-xida-msft
Community Support
Community Support

Hi @OsmandFernando

Could you please share a bit more about your scenario?

Do you want the latest item to be displayed at the top of your Gallery? Why do you not use Sort function in your app?

How many records existed in your data source? More than 2000?

 

Currently, if you want to display the latest item from your data source at the top of your Gallery without Sort function, I afraid that there is no direct way to achieve your needs in PowerApps currently.

 

As an alternative solution, I think the ForAll function and LastN function could achieve your needs. I have made a test on my side, please consider take a try with the following workaround:

Set the OnStart property of App to following:

Clear(FinalCollection);
ForAll(
       [1,2,3,4,5,6,7,8,9,10,...,100,101,...., 200, 201, ...],
       Collect(FinalCollection, First(LastN('Item Master', Value)))
)

Then modify your Filter formula as below:

If(
   IsBlank(TextSearchBox1),
   FinalCollection,
   Search(
          AddColumns(FinalCollection,"Model",'Model Number'),
          TextSearchBox1.Text, "Model","ItemName"
   )
)

then re-load your app (fire the OnStart property of the App), check if the issue is solved.

Note: Please consider set the "Data row limit for Non-delegable queries" option to maximum value -- 2000 within Advanced settings of App settings of your app.

 

As an direct solution, I think the Sort function or SortByColumns function could achieve your needs perfectly.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Dear @mdevaney your suggestion fulfilled my need. Thank you so much

 

@v-xida-msft  Thank you for your wonderful reply too. 

 

Osmand.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,219)