cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

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

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

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support Team
Community Support Team

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

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

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Super User
Super User

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

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. 

View solution in original post

10 REPLIES 10
Super User
Super User

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

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

Community Support Team
Community Support Team

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

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 Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

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

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. 

 

Community Support Team
Community Support Team

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

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

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Super User
Super User

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

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. 

View solution in original post

Super User
Super User

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

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.

Super User
Super User

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

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

 

Super User
Super User

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

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. 

 

 

Highlighted
Super User
Super User

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

@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

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (3,875)