Displaying sum of Duration as hours

When I do a table.duration.sum(), I get output as X Days Y Hours and Z minutes. I am looking to get output as X hours- could someone point me to the right direction.

I would also like to have the page display total number of hours spent on

(a) the current day.

For example, “total time spent today = A hours”

(b) Current week.

For example, “total spent time this week (Sunday to today) = B hours”

Would be grateful for any help with the formula to achieve the above. Thank you.

Hi @LJ_P , welcome to the community.

A good practice is to share a doc so other can check easily on what you mean. However this time maybe this will help you out

step one is the step two without the part in yellow, thus the basic filter based on the week number.

I hope it helps, cheers, Christiaan

2 Likes

Just a small complement, to the ToHours() suggestion by @Christiaan_Huizer :blush:

You could get your total of hours for today in a canvas formula using something like this :

Format(
  "{1} {2}",
  Durations.Filter(Date = Today()).Duration.Sum().ToHours(),
  If(Durations.Filter(Date = Today()).Duration.Sum().ToHours() <= 1,"hour","hours")
)

Format() creates a text value based on a template where you can use placeholders. Here, the template is "{1} {2}".

The 1st placeholder ({1}) is for total of hours for today …

Durations.Filter(Date = Today()).Duration.Sum().ToHours()

… And what it does is it take the table called Durations (see sample below :blush: ) filter the dates in the Date column and keep only the ones where Date = Today(), then for those rows it goes and look for the corresponding values in Duration… Sum those Duration and converts the result as hours with ToHours :blush: .

The 2nd placeholder ({2}) is completely optional and could be replaced by “hours” in the template (:innocent: - i.e.: using "{1} hours" as a template in Format() instead of "{1} {2}"), as it is just there to write “hour” in its singular form or plural one :blush: .

For the total hours for this week, it’s kind of the same formula :blush:

Format(
  "{1} {2}",
  Durations.Filter(Week = Today().WeekNumber()).Duration.Sum().ToHours(),
  If(Durations.Filter(Week = Today().WeekNumber()).Duration.Sum().ToHours() <= 1,"hour","hours")
)

… But, for the 1st placeholder ({1}), instead of filtering the Durations table by Date, it filters the column called Week and keep only the rows where Week = Today().WeekNumber() :blush: .

Once again, the 2nd placeholder could be replaced by “hours” in the Template of the Format() :blush: .

This would be feasible with Concatenate() too :blush: .

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.