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 / ClearCollect, Group By...
Power Apps
Unanswered

ClearCollect, Group By, Nested Gallery

(0) ShareShare
ReportReport
Posted on by 55

Hello! I'm hoping to get some assistance with this item in PowerApps that I am trying to do.

I have a SharePoint called Tracker that has columns for StartTime, EndTime, and Item (Item is Title). StartTime and EndTime are both "Date and Time" columns, while everything else is numbers.

There are multiple items (A, B, C) that each have start and end times.

I have a second SharePoint called Counts that has column DateTime that is also a "Date and Time" column, as well as columns for "Total", "Item A", "Item B", and "Item C".

I want to have three galleries that are nested within each other.

The first gallery is for the headers - it collects the dates and times, specifically from the EndTime column. It creates a gallery that looks like:

Date: 11/1/2023 | Time: 10:00

Date: 11/1/2023 | Time: 11:00

Date: 11/1/2023 | Time: 12:00

etc.

 

This gallery seems to work properly.

 

OnStart (App)

 

ClearCollect(
 colTracker,AddColumns('Tracker',"Distinct_Time", Hour(EndTime),"Distinct_Date",DateValue(EndTime)))

ClearCollect(
 colCombined,Counts,'Tracker')

 

 

Gallery 1 - Items

GroupBy(colTracker,"Distinct_Date","Distinct_Time","DATA")

Gallery 1 - Text Label

"Date: " &(ThisItem.Distinct_Date)&" | Time: " &(ThisItem.Distinct_Time) &":00"

The second gallery is for the counts of each item - it should collect the counts of how many rows have a title of that item that falls within those times. It should look something like this:

Date: 11/1/2023 | Time: 10:00All Items: 18Item A: 6Item B: 6Item C: 6

Date: 11/1/2023 | Time: 11:00All Items: 20Item A: 4Item B: 7Item C: 9

Date: 11/1/2023 | Time: 12:00All Items: 9Item A: 3Item B: 3Item C: 3

Gallery 2 - Items

ThisItem.DATA

Gallery 2 - Text Label (All)

CountRows(Filter(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date))

Gallery 2 - Text Label (Item A)

CountRows(Filter(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date&&Title="Item A"))

Gallery 2 - Text Label (Item B)

CountRows(Filter(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date&&Title="Item B"))

Gallery 2 - Text Label (Item C)

CountRows(Filter(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date&&Title="Item C"))

This gallery calculates correctly, but it repeats itself. For example, I get 18 repeating items for 11/1/23 at 10:00.

How can I make the data only appear once? I have tried using Distinct() but I get a series of errors when I try that. 

 

Here are a few things I've tried:

CountRows(Filter(Distinct(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date)))

Invalid number of arguments: received 1, expected 2 or more.

CountRows(Distinct(Filter(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date)))

Invalid number of arguments: received 1, expected 2 or more.

Distinct(CountRows(Filter(colTracker,Hour(ThisItem.EndTime)=Distinct_Time&&DateValue(ThisItem.EndTime)=Distinct_Date)))

Invalid number of arguments: received 1, expected 2 or more.

Distinct(ThisItem.DATA)

Invalid number of arguments: received 1, expected 2.

Distinct(ThisItem.DATA,EndTime)

This causes the text label to show as: "Name isn't valid. EndTime isn't recognized"

 

The third gallery comes from SharePoint Counts and ideally would match the counts (not row counts, these are just numbers) to the date/time.

Gallery 3 - Items

colCombined

Gallery 3 - Text Label (Item A)

If(ThisItem.DateTime=ThisItem.EndTime,'Item A')

This one I am struggling to find the code for both the items and the text labels themselves. I think I need to be combining it back to the distinct time I used above, but I'm not sure. I know that the data is not connecting properly because I can't see them in the table.

Any suggestions on how to get the values I am looking for?

Thank you! Much appreciated for any information on both.

Categories:
I have the same question (0)
  • M_Ali_SZ365 Profile Picture
    1,110 on at

    Hi @dsopshin,

    please try This

    Gallery 2 - Items
    GroupBy(colTracker, "Distinct_Date", "Distinct_Time", "GroupedData")
    
    Gallery 2 - Text Label (All Items)
    "Date: " & ThisItem.Distinct_Date & " | Time: " & ThisItem.Distinct_Time & ":00" & 
     " All Items: " & CountRows(ThisItem.GroupedData) &
     " Item A: " & CountIf(ThisItem.GroupedData, Title = "Item A") &
     " Item B: " & CountIf(ThisItem.GroupedData, Title = "Item B") &
     " Item C: " & CountIf(ThisItem.GroupedData, Title = "Item C")
    Gallery 3 - Items
    colCombined
    
    Gallery 3 - Text Label (Item A)
    "Item A: " & LookUp(colCombined, DateTime = ThisItem.Distinct_Date && Item = "Item A").Total
    
    Gallery 3 - Text Label (Item B)
    "Item B: " & LookUp(colCombined, DateTime = ThisItem.Distinct_Date && Item = "Item B").Total
    
    Gallery 3 - Text Label (Item C)
    "Item C: " & LookUp(colCombined, DateTime = ThisItem.Distinct_Date && Item = "Item C").Total

    If this solution resolves your issue, please consider marking it as accepted. ✅

    Warm regards,
    Muhammad Ali

  • dsopshin Profile Picture
    55 on at

    @M_Ali_SZ365 

    Thank you for the reply!

    For Gallery 2, now rather than getting the same data 18 times, I get a duplicate list of all items (hundreds) on each entry from Gallery 1.

    For Gallery 3, I get an error for .Total (the error is: Name isn't valid. Total isn't recognized).

     

    Thanks!

     

     

  • M_Ali_SZ365 Profile Picture
    1,110 on at

    Hi @dsopshin ,

    I apologize for the confusion. Let's address the issues:

    Gallery 2 - Items:
    It seems like the grouping is causing duplication. To resolve this, try modifying the GroupBy expression:

    GroupBy(colTracker, "Distinct_Date", "Distinct_Time", "GroupedData")

    Make sure the GroupBy expression includes all the necessary columns. Then, in the Text Label for All Items, use the CountRows function directly on the grouped data:

    "Date: " & ThisItem.Distinct_Date & " | Time: " & ThisItem.Distinct_Time & ":00" &
    " All Items: " & CountRows(ThisItem.GroupedData) &
    " Item A: " & CountIf(ThisItem.GroupedData, Title = "Item A") &
    " Item B: " & CountIf(ThisItem.GroupedData, Title = "Item B") &
    " Item C: " & CountIf(ThisItem.GroupedData, Title = "Item C")

    Gallery 3 - Text Label (Item A, Item B, Item C):
    It appears that the "Total" column is not recognized in your SharePoint list. Make sure that the column name is correct. If it's not named "Total," replace it with the correct column name.

    For example:

    Gallery 3 - Text Label (Item A)
    "Item A: " & LookUp(colCombined, DateTime = ThisItem.Distinct_Date && Item = "Item A").YourColumnName
    
    Gallery 3 - Text Label (Item B)
    "Item B: " & LookUp(colCombined, DateTime = ThisItem.Distinct_Date && Item = "Item B").YourColumnName
    
    Gallery 3 - Text Label (Item C)
    "Item C: " & LookUp(colCombined, DateTime = ThisItem.Distinct_Date && Item = "Item C").YourColumnName

    Replace YourColumnName with the actual column name containing the counts.

    I hope this helps. Let me know if you encounter any further issues!

    Best regards,
    Muhammad Ali

  • dsopshin Profile Picture
    55 on at

    @M_Ali_SZ365 Thanks for the help!

    Gallery 2 - still showing a repeated gallery for each gallery 1 item. I'm not sure why it's still repeating. 

    Gallery 3 - no longer being an error, but now still showing as no value.

     

    Thanks!

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 395

#2
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 287 Super User 2026 Season 1

Last 30 days Overall leaderboard