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 / Sum hours in "##:##" f...
Power Apps
Answered

Sum hours in "##:##" format in a Collection Column

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello, 


I'm having trouble here hope someone can assist. 

 

I'm trying to sum an hours column in a Collection. The Collection has a column (duration) with values such as "02:00" (two hours) and "05:30" (five hours, thirty minutes). I want to sum these columns.

 

I'm using a Textbox control with its Default property set to: 

Text(
 Sum(
 workSummary,
 duration),
 "[$-en-US]##:##"
)

I have no errors showing in the Text box, but no values appear when the collection is populated with hours. What am I missing here? 

 

Thanks

 

Categories:
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    ahh! This is driving me nuts. Need help please!

     

    Why does this work to Sum the hours: 

    Sum(
     colWorkSummary.hours, hours)

    Results in "10" when two "05:00" activities are added to the Collection, but stays "10" when an additional "00:30" is added (not picking up the Minutes)

     

    This doesn't work to Sum the hours, a ":", and the minutes in the Collection!

    Concatenate(
     Sum(
     colWorkSummary.hours, hours),
     ":",
     Sum(
     colWorkSummary.minutes, minutes)
    )

    ahh! Any help out there for Sum'ing a column in a Collection?

     

    Thanks

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @ericonline,

     

    Could you please share a bit more about the collection (workSummary) that you mentioned within your app?

    Do you want to sum hours within the duration column of the collection (workSummary) and format the result as "##:##"?

     

    I have made a test on my side, if you want to sum an hours column in a Collection using Sum function and Text function, I afraid that there is no way to achieve your needs in PowerApps currently.

     

    As an alternative solution, you could consider take a try to create two collections to store hours and minutes separately. I have made a test on my side, please take a try with the following workaround:4.JPG

     

    5.JPG

     

     

    Set the OnVisible property of the screen to following formula:

    ClearCollect(workSummary,{duration:"02:30"},{duration:"03:00"},{duration:"01:00"},{duration:"00:15"});
    ForAll(
    workSummary,
    Collect(HoursCollection,First(Split(duration,":")));
    Collect(MinutesCollection,Last(Split(duration,":")))
    )

    On your side, you should type the following formula:

    ForAll(
    workSummary,
    Collect(HoursCollection,First(Split(duration,":")));
    Collect(MinutesCollection,Last(Split(duration,":")))
    )

     

    Set the Text property of the Label control to following formula (On your side, set the Default property of the TextInput control to following😞

    If(
    Len(Text(RoundDown(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result))/60,0)))=1,
    Concatenate(
    "0",
    Text(RoundDown(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result))/60,0)),
    ":",
    Text(Mod(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result)),60))
    ),
    Concatenate(
    Text(RoundDown(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result))/60,0)),
    ":",
    Text(Mod(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result)),60))
    )
    )

     

    Best regards,

    Kris

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-xida-msft, thank you for spending your time on this. I believe this should be easier. 

     

    Here is the colWorkSummary details: 
    Input UI: 

    sumHours1.png

     

    Add "+" Button: 

    Collect(colWorkSummary,
     {
     id: CountRows(colWorkSummary) + 1,
     event_type: activityType.Selected.Value,
     event_detail: activityDetail.Selected.Value,
     duration: Concatenate( 
     activityDurationHour.Selected.Value,
     ":",
     activityDurationMinute.Selected.Value),
     comments: If( 
     IsBlank(activityComments.Text),
     "No comments",
     activityComments.Text)
     })

    Output UI: 

    sumHours2.png

     

    I want to sum the "08:00" and "02:00". 

     

    Need a Function for the Total Hours label shown above. 

     

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @ericonline,

     

    Have you taken a try with the solution that I provided?

     

    I think the solution that I provided could achieve your needs. On your side, please take a try with the following workaround:

     

    Set the OnSelect property of the Add "+" button to following formula:

     

    Collect(colWorkSummary,
     {
     id: CountRows(colWorkSummary) + 1,
     event_type: activityType.Selected.Value,
     event_detail: activityDetail.Selected.Value,
     duration: Concatenate( 
     activityDurationHour.Selected.Value,
     ":",
     activityDurationMinute.Selected.Value),
     comments: If( 
     IsBlank(activityComments.Text),
     "No comments",
     activityComments.Text)
     }
    );
    Clear(HoursCollection);
    Clear(MinutesCollection);
    ForAll(
     colWorkSummary,
     Collect(HoursCollection,First(Split(duration,":")));
     Collect(MinutesCollection,Last(Split(duration,":")))
    )

     

    Set the Text property of the Label control to following formula:

    If(
     Len(Text(RoundDown(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result))/60,0)))=1,
     Concatenate(
     "0",
     Text(RoundDown(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result))/60,0)),
     ":",
     Text(Mod(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result)),60))
     ),
     Concatenate(
     Text(RoundDown(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result))/60,0)),
     ":",
     Text(Mod(Sum(60*Sum(HoursCollection,Result),Sum(MinutesCollection,Result)),60))
     )
    )

     

    Best regards,

    Kris

     

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I will try it though it will add a fair amount of complexity to the app.

     

    Are other PowerApps users (more novice) expected to follow this method as well? I feel like adding multiple time values like this will be a common use case that PowerApps might want to ease. 

     

    Either way, I really appreciate the efforts you provided. I will implement and let you know how it works. 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-xida-msft, I implemented your idea but the results are not calculating correctly. 

     

    OnSelect of "Add" icon: 

    Collect(colWorkSummary,
     {
     id: CountRows(colWorkSummary) + 1, 
     event_type: activityType.Selected.Value, 
     event_detail: activityDetail.Selected.Value,
     duration: Concatenate( 
     activityDurationHour.Selected.Value,
     ":",
     activityDurationMinute.Selected.Value),
     comments: If( 
     IsBlank(activityComments.Text),
     "No comments",
     activityComments.Text)
     });
    
    ForAll(
     colWorkSummary,
     Collect(
     colHours,
     First(
     Split(duration, ":")));
     Collect(
     colMinutes,
     Last(
     Split(duration, ":")))
    )

    Text box: 

    If(
     Len(
     Text(
     RoundDown(
     Sum(60*Sum(
     colHours,Result),
     Sum(
     colMinutes,Result))/60,0)))=1,
     Concatenate(
     "0",
     Text(
     RoundDown(
     Sum(60*Sum(
     colHours,Result),
     Sum(
     colMinutes,Result))/60,0)),
     ":",
     Text(
     Mod(
     Sum(60*Sum(
     colHours,Result),
     Sum(
     colMinutes,Result)),60))
     ),
     Concatenate(
     Text(
     RoundDown(
     Sum(60*Sum(
     colHours,Result),
     Sum(
     colMinutes,Result))/60,0)),
     ":",
     Text(
     Mod(
     Sum(60*Sum(
     colHours,Result),
     Sum(
     colMinutes,Result)),60))
     )
    )

    When adding the two times shown below, the results are 2:30 off: 

    sumTime.png

     

    PS: I accidently accepted my own post as a Solution instead of hitting reply! Sorry. The buttons were cutoff on my screen. I'll definitely accept your post as a solution as well.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hello @v-xida-msft. In debugging this more (with my awesome daughter 🙂 ), we found that the hours are adding +2, +3, +4, +5 etc to each hour summed.

     

    Example: Here I add 1 hour repeatedly and you can see the findings.

    sumTime.gif

     

    I can't quite tell where in your functions this is occurring. Can you see it? 

     

    Thanks

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @v-xida-msft! Your solution did indeed work as you laid it out... I missed the Clear functions before the Collect.

     

    I thank you so very much for the energy you put into this solution. You're very skilled. 

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @v-xida-msft, do you have ideas for how I can get the last "0" on the end when "00" mins are in colMinutes?

     

    dropdownCollection5.png

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @v-xida-msft wow! I've been dissecting this code for a while on the whiteboard.... this is really smart stuff. Great work again! Wish I could double-Kudo!

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 411 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 338

#3
WarrenBelz Profile Picture

WarrenBelz 256 Most Valuable Professional

Last 30 days Overall leaderboard