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

Count gallery items not working (Project Oakdale)

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

11 REPLIES 11
WarrenBelz
Super User III
Super User III

Hi @freddiejoseph1 ,

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.

Hey Warren,

 

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

 

freddiejoseph1_0-1612296881533.png

 

 

Thanks,

 

Freddie

@freddiejoseph1 ,

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.

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
)
)

 

Thanks @freddiejoseph1 ,

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.

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

@freddiejoseph1 ,

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.

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)

@freddiejoseph1 ,

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.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (54,361)