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 / Collection groupby Tit...
Power Apps
Answered

Collection groupby Title, count of rows and Difference of Last item created and the first item

(0) ShareShare
ReportReport
Posted on by 6

Hi,

 

I have a Collection and I trying to group by with count of rows and difference of the time. 

 

TitleTime Created
Test A9:00 AM
Test A10:00 AM
Test B11:00 AM
Test B1:00 PM

 

I am looking to get the result something like this:

 

TitleCount of rowsTimeDiff (hrs)
Test A21
Test B22

 

I can get the group by for count of rows but unable to get the timediff.

did any one have this before. appreciate any formulas.

 

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @AIBuild4Com 

    Can you explain and/or clarify that you will only have 2 rows of any particular type?  

    For the purposes of the time difference, you would want to compare two times.  If you have more rows than 2, then the question would be - what would you then use to compare?

     

     

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    Microsoft Employee on at

    Hi@AIBuild4Com,

    Based on the issue that you mentioned, do you want to add 2 columns 'Count of rows' and 'TimeDiff (hrs)' to store the corresponding values?

    Could you please share a bit more about the scenario, how you collect your first collection as the first screenshot?

    The key to calculating the 'TimeDiff (hrs)' is to avoid the disambiguation problem.

    I have a test on my side, please take a try as below:

    Create a collection Col1 like yours to start my test. (set the OnSelect property of the Button)

     

    Collect(Col1,{Title:"TestA",'Time Created':"9:00 AM"},{Title:"TestA",'Time Created':"10:00 AM"},{Title:"TestB",'Time Created':"11:00 AM"},{Title:"TestB",'Time Created':"1:00 PM"})

     

    Note: Here the 'Time Created' becomes Text values.

    Col1.png

    Add the 2nd Button and set the OnSelect property as below:

     

    Collect(Col2,AddColumns(GroupBy(Col1,"Title","GroupTitle"),"Count of rows",CountRows(GroupTitle)))

     

    Note: After this, you could get the 'Count of rows' column.

    Col2.png

    Add the 3rd Button and set the OnSelect property as below:

     

    Collect(Col3,AddColumns(Col2,"TimeDiff (hrs)",DateDiff(TimeValue(First(Filter(Col1,Title=Col2[@Title])).'Time Created',"en-US"),TimeValue(Last(Filter(Col1,Title=Col2[@Title])).'Time Created',"en-US"),Hours)))

     

    Col3.png

    Hope this could help you.

    Best Regards,

    Qi

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 204 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard