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

Display last 3 items and increase number of items displaying on screen

Hello all!

 

I'm currently using the code below to filter news based on specific categories selected on previous screen. 

 

Filter(your_datasource_name, Category.Value = currentCategory)

I have a lot of items for each category and I think the view on the second screen is restricted to show only a certain number of items for each category so I can only see the items of the last category I click on and I'm not seeing the items from others. 

How can I set a filter to display last 3 items of each category selected instead of all? 

 

Also, How can I increase the number of items showing on screen? 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz Community Champion
Community Champion

Re: Display last 3 items and increase number of items displaying on screen

Hello @Fnu ,
How do you define the last 3 (the newest three?)
If this is the case, use

FirstN(
   Sort(
      Filter(
         your_datasource_name, 
         Category.Value = currentCategory
      ),
      ID,
      Descending
   ),
   3
)

for the records wit the highest ID numbers, these being the last three saved.
If you are still concerned about limited numbers (using the your filters this should not happen), please send a screen shot of the gallery.

 

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

10 REPLIES 10
WarrenBelz Community Champion
Community Champion

Re: Display last 3 items and increase number of items displaying on screen

Hello @Fnu ,
How do you define the last 3 (the newest three?)
If this is the case, use

FirstN(
   Sort(
      Filter(
         your_datasource_name, 
         Category.Value = currentCategory
      ),
      ID,
      Descending
   ),
   3
)

for the records wit the highest ID numbers, these being the last three saved.
If you are still concerned about limited numbers (using the your filters this should not happen), please send a screen shot of the gallery.

 

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

Fnu Helper I
Helper I

Re: Display last 3 items and increase number of items displaying on screen

Hi Warren, 

 

I want to sort by date (Items published from last 3 days). Sorry about that. 

WarrenBelz Community Champion
Community Champion

Re: Display last 3 items and increase number of items displaying on screen

Ok @Fnu ,
I just corrected an error in the post anyway (you would have received the first three).
One thing here - unless you have a time on the date, you could have six on the same date in the first three and I am not sure which three of the six the below filter would show, however the below will work - I will call the date field  PublishedDate

FirstN(
   Sort(
      Filter(
         your_datasource_name, 
         Category.Value = currentCategory
      ),
      PublishedDate,
      Descending
   ),
   3
)

Also I just tested it on a larger (5,000 + item) data set and it took quite a while to load. you might consider the following - make a collection

ClearCollect(
   colCategory,
   Filter(
      your_datasource_name, 
      Category.Value = currentCategory
   )
)

The Items of your gallery would be

FirstN(
   Sort(
      colGallery,     
      PublishedDate,
      Descending
   ),
   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.

Fnu Helper I
Helper I

Re: Display last 3 items and increase number of items displaying on screen

Hi Warren,

 

The first formula works great. 

 

I tried the clearcollect formula with OnSelect function and it's giving me an error. Is this supposed to be used with buttons or on the previous screen or same screen as the items are being displayed? Also is there any other value that needs to be changed besides the datasourcename? 


Thanks for your help! 

 

WarrenBelz Community Champion
Community Champion

Re: Display last 3 items and increase number of items displaying on screen

Hi @Fnu ,

I picked up this thread without realising @mdevaney had requested you to post it. I provided an earlier suggestion on your first post (I posted concurrently with @mdevaney ), and now see he has sorted out that one, but you still have issues you need clarified.

If I am understanding you correctly, the original request was around displaying a category selected by the user and now you are asking if the last three by date from each category can be displayed. I will assume these categories are from a list, so you know the possibilities and do not have to ask the system to find them. I will use Pending, Active and Finalised in the example below.   

Concurrent(
   ClearCollect(
      colActive,
      FirstN(
         Sort(
            Filter(
               your_datasource_name, 
               Category.Value = "Active"
            ),
            PublishedDate,
            Descending
         ),
         3
      )
   ),
   ClearCollect(
      colPending,
      FirstN(
         Sort(
            Filter(
               your_datasource_name, 
               Category.Value = "Pending"
            ),
            PublishedDate,
            Descending
         ),
         3
       )
   ),
   ClearCollect(
      colFinal,
      FirstN(
         Sort(
            Filter(
               your_datasource_name, 
               Category.Value = "Finalised"
            ),
            PublishedDate,
            Descending
         ),
         3
      )
   )
);
ClearCollect(
   colLastThree,
   colActive,
   colPending,
   colFinal
)

Your gallery if you wanted sorted then by PublishedDate would then be

Sort(
   colLastThree,
   PublishedDate,
   Descending
)

 

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.

WarrenBelz Community Champion
Community Champion

Re: Display last 3 items and increase number of items displaying on screen

Hi @Fnu ,
I received this question after I posted the last one - just noticed I left a comma out after the collection name (free-typing code is always problematic). You also need to set the Variable currentCategory as per @mdevaney 's post and set it to the button value when you press it.

ClearCollect(
   colCategory,
   Filter(
      your_datasource_name, 
      Category.Value = currentCategory
   )
)

The rest should work

 

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.

Fnu Helper I
Helper I

Re: Display last 3 items and increase number of items displaying on screen

Hi @WarrenBelz,

 

Thank you for your help. 

 

The code below works but its displaying all the categories. I don't want to go back and forth between the threads so I'll just mention it here again. I appreciate your help with this. 

 

I have two screens.  

 

Screen1 contains buttons labelled with categories (Red, Blue, Orange, Yellow)

Screen2 contains gallery

User can select one or more categories from Screen1

When user selects categories, he clicks on a NextScreen button that navigates to Screen2. Screen2 should only display items from selected categories. 

 

If the user goes back and "unselects" a category, it should not display in the gallery anymore. 

 

Right now, it shows all the categories regardless of the selection. 

 

can you please confirm which formula will go on which screen and with which control? 

 

Please let me know if I need to explain better.

Highlighted
WarrenBelz Community Champion
Community Champion

Re: Display last 3 items and increase number of items displaying on screen

Hi @Fnu ,

The whole issue that mislead both @mdevaney and myself was your reference to "Buttons".

A Button in PowerApps terms is something different to what you have - which seems to be check boxes where the user can select more than one. I assume you run the screen transition off another Button as we know it.

So using Red, Blue, Orange and Yellow and calling the check boxes RedBox, BlueBox, OrangeBox and YellowBox

ClearCollect(
   colCategories,
   Filter(
      your_datasource_name, 
      If(
         RedBox.Value = true,   
         Category.Value = "Red"
      ) &&
      If(
         BlueBox.Value = true,   
         Category.Value = "Blue"
      ) &&
      If(
         OrangeBox.Value = true,   
         Category.Value = "Orange"
      ) &&
      If(
         YellowBox.Value = true,   
         Category.Value = "Yellow"
      )
   )
)

Your gallery Items could then be

Sort(
   colGallery,     
   PublishedDate,
   Descending
)

For the first three of each as before (this is getting really complex and I cannot test it) - you may have to check on brackets and commas if you get an error, however the structure and logic should work.

// Create empty collection so the concatention at the bottom will work if anybox uchecked.
ClearCollect(colRed,{});
ClearCollect(colBlue,{});
ClearCollect(colOrange,{});
ClearCollect(colYellow,{});
// Now conditionlly get the last three records of categories selected
Concurrent(
   If(
      RedBox.Value = true,
      ClearCollect(
         colRed,
         FirstN(
            Sort(
               Filter(
                  your_datasource_name, 
                  Category.Value = "Red"
               ),
               PublishedDate,
               Descending
            ),
            3
         )
      )
   ),
   If(
      BlueBox.Value = true,
         ClearCollect(
         colBlue,
         FirstN(
            Sort(
               Filter(
                  your_datasource_name, 
                  Category.Value = "Pending"
               ),
               PublishedDate,
               Descending
            ),
            3
         )
      )
   ),
   If(
      OrangeBox.Value = true,
      ClearCollect(
         colOrange,
         FirstN(
            Sort(
               Filter(
                  your_datasource_name, 
                  Category.Value = "Orange"
               ),
               PublishedDate,
               Descending
            ),
            3
         )
      )
   ),
   If(
      YellowBox.Value = true,
      ClearCollect(
         colYellow,
         FirstN(
            Sort(
               Filter(
                  your_datasource_name, 
                  Category.Value = "Yellow"
               ),
               PublishedDate,
               Descending
            ),
            3
         )
      )
   )
);
// Now put all the collections together
ClearCollect(
   colCategories
   colRed,
   colBlue,
   colOrange,
   colYellow
)

Your gallery if you wanted sorted then by PublishedDate would then be

Sort(
   colCategories,
   PublishedDate,
   Descending
)

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.

 

Fnu Helper I
Helper I

Re: Display last 3 items and increase number of items displaying on screen

Hi Warren, 

 

I was actually using buttons instead of checkboxes. That's what happens when you're new to a platform. Thanks for your help!

Helpful resources

Announcements
secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (6,181)