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 Platform Community / Forums / Power Apps / Count gallery items no...
Power Apps
Unanswered

Count gallery items not working (Project Oakdale)

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all,


I have a gallery with two nested galleries within it to show some dataverse items based on some filtering. One of the filters is the date of the data row needs to be between two dates which the user chooses from two date pickers. The screen looks like this currently:

 

freddiejoseph1_0-1612292948164.png

 

I cannot get the two fields which are highlighted to show the correct number of items. The top highlight number is supposed to show all the items in the dataverse between the two dates selected + filtered by the partner dropdown. The second highlighted number (currently showing 6) is supposed to be a total of all the items that fall into the Buyers Enquiries (etc) category which shows on the left hand side. These numbers are not correct.

The formula I have for the total calls item property is:

If(drpPartner.SelectedText.Value = "All Partners",

CountIf(DateRange, true && Date >= DatePickerStart.Value And Date <= DatePickerEnd.Value),

CountIf(DateRange, Partner = drpPartner.SelectedText.Value && Date >= DatePickerStart.Value And Date <= DatePickerEnd.Value))

 

DateRange is a collection which is collected when the screen is visible but also when any of the filters change:

ClearCollect(DateRange, Filter(AllCalls, Date >= DatePickerStart.Value And Date <= DatePickerEnd.Value))

For the second highlighted number (currently showing 6) the text formula is: ThisItem.Count.

 

Any help would be much appreciated

Categories:
  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @Anonymous ,

    Try this

    CountIf(
     DateRange, 
     Date >= DatePickerStart.SelectedDate && Date <= DatePickerEnd.SelectedDate &&
     (
     drpPartner.Selected.Value = "All Partners" ||
     Partner = drpPartner.Selected.Value
     )
    )

     

    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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hey Warren,

     

    That still doesn't work 😕 the total number is still incorrect.

     

    freddiejoseph1_0-1612296881533.png

     

     

    Thanks,

     

    Freddie

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @Anonymous ,

    You don't actually need the DatePicker filter in the formula if you are already doing this in the collection, but it still should work as it is doing the same filter. What total are you expecting? Also if you put CountRows(DateRange) on a label does this give the total you want without the other filter?

    Also what is ThisItem.Count refer to?

     

    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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks for replying Warren,

     

    I have changed the date to show the problem a bit better. Here you can see the total calls is showing as 8, but if you add up all of the numbers from the rows on the left hand side of the gallery they total more than 8. There are in fact 15.

     

    freddiejoseph1_0-1612298689401.png

     

    A label containing CountRows(DateRange) gives the same result as the total calls label.

     

    ThisItem.Count refers to the numbers that go down the right hand side of the gallery. They are supposed to be a total count of items but filtered by the headers/categories. Count is a column which is added to the DateRange collection in the items property of the gallery (sorry for the length of this bit of code):

    If(
    drpPartner.SelectedText.Value = "All Partners",
    SortByColumns(
    AddColumns(
    GroupBy(
    DateRange,
    "crb24_department",
    "ByDepartment"
    ),
    "Count",
    CountRows(ByDepartment)
    ),
    "Count",
    Descending
    ),
    Filter(
    SortByColumns(
    AddColumns(
    GroupBy(
    DateRange,
    "crb24_partner",
    "crb24_department",
    "ByDatePartner"
    ),
    "Count",
    CountRows(ByDatePartner)
    ),
    "Count",
    Descending
    ),
    crb24_partner = drpPartner.SelectedText.Value
    )
    )

     

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Thanks @Anonymous ,

    Back to basics here as I still do not clearly understand your issue (from a code perspective) This code 

    With(
     {
     wDates:
     Filter(
     DateRange,
     drpPartner.Selected.Value = "All Partners" || 
     crb24_partner = drpPartner.Selected.Value
     )
     },
     SortByColumns(
     AddColumns(
     GroupBy(
     wDates,
     "crb24_partner",
     "crb24_department",
     "ByDatePartner"
     ),
     "Count",
     CountRows(ByDepartment)
     ),
     "Count",
     Descending 
     )
    )

    will take the collection DateRange and

    • either show all records OR
    • show those filtered buy the drop down THEN
    • Group by the unique combinations partner and department AND
    • Add a row with the named Count (I suggest you change this as it is a Reserved Word in Power Apps) with the total items in each group (this total will either be the full count of DateRange OR the number of items matching the filter) THEN
    • Sort the result by that number descending

    What is it in there that you do not want to do?

     

    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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hey Warren,

     

    That is exactly what I want to do. And the code you provided works (I have made a few minor changes: With({wDates: Filter(DateRange, drpPartner.SelectedText.Value = "All Partners" || crb24_partner_1 = drpPartner.SelectedText.Value)}, SortByColumns(AddColumns(GroupBy(wDates, "crb24_partner_1", "crb24_enquirytype", "ByDatePartner"), "RowNumber", CountRows(ByDatePartner)), "RowNumber", Descending))

     

    But the Total calls number in the top right of the screen still does not match the number of calls which are displayed in the gallery. Total calls shows 13 but there are definitely more than 13 calls in the gallery, I have highlighted what I mean.

     

    freddiejoseph1_0-1612342050717.png

     

     

    Thanks,

     

    Freddie

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @Anonymous ,

    That is why I asked about ThisItem.Count earlier (if the bottom one is correct, then this one is wrong). This control I assume is in the top form - how is Count calculated there and how is the gallery related to the form (what is the Item of the Form)?

     

    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.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    ThisItem.Count I believe was counting the number of items which appeared in the column I added called "Count" in the collection DateRange. I have now changed that to ThisItem.RowNumber (which is what I changed the "Count" column to 🙂 )

     

    The code for total calls is: CountRows(DateRange)

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @Anonymous ,

    So unfiltered (All Partners), that should be the same total - you are simply counting exactly what you have grouped and totalled - put a label on the screen with the same formula and see if you get this result. If you filter however, this will be a amount greater than the total of the groups.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Yeah so that is where I am struggling. How can I get the total number all the items in the left hand side of the gallery to show correctly in the total calls box? I cannot work out what code is required. CountRows(DateRange) does not work here

    freddiejoseph1_0-1612347296937.png

     

    And how can I get the total number filtered by category to show here. ThisItem.RowNumber does not work here:

    freddiejoseph1_1-1612347335508.png

     

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard