Adding time values


#1

I have a repeater with a Time column showing values in hh:mm (e.g. 00:18). I have a footer underneath my repeater and I’d like to show the total time value. For example, 00:18 plus 01:12 would show 01:30. Is this possible?


#2

You could do this a few ways… Depends on how your time values are represented/stored in your repeater.

I would recommend you use an absolute time value with units in seconds to represent time in your repeater cell. It makes the “time math” a snap. For instance, in your repeater sheet, your “Time” column would have values of 18 and 72 for your two time examples. You would need to convert the time value from seconds to “standard colon-delimited time display”, e.g, from 72 to 01:12, everywhere you show it, like in the repeater’s OnItemLoad code. Here is a good description and formula for that:
https://forum.axure.com/t/how-to-generate-a-time-duration-from-number-of-minutes/28443/5?u=mbc66

If you want to keep your time values represented as time-formatted text, you’ll need to do the inverse of that formula in your summation to get the number of seconds in each cell then convert back to colon-delimited strings, which is a bit of extra converting, but probably keeps your spreadsheet easier to read/edit/import.

Here is an example that does both. The Home page has a repeater with time stored as “elapsed seconds” and Page 1 has time stored with colon-delimited strings.
TimeSummation.rp (92.0 KB)


#3

Great, that’s fantastic! I used your “Page 1” method so I could keep the time formatted as it was.

Many thanks


#4

Hi again, I’m hoping you can help me with another small issue?

In the same repeater I have an Amount column, which also shows a total in the footer. I’ve done this by setting a variable (SumAmount) to [[SumAmount + Item.Col9]] and then setting the text on the Total footer cell to [[SumAmount.toFixed(2)]].

This works okay when the repeater initially loads, however, as soon as I add a new row to the repeater the total becomes screwed. For example, if there are rows with 90.00 and 360.00 then to total equals 450.00, but if I add a row that contains an amount of 30.00, the total increases to the 930.00 instead of 480.00!

Any ideas?


#5

Hi @jopsmith,

You probably need to reset your variable to 0 when the repeater starts loading items. When you add a row to the repeater, it reloads all the items, which is re-triggering all of your addition and so the total is doubled, plus the new 30 that you added.

You can add a conditional case: If [[Item.isFirst]] equals true, then set the text on the Total footer cell to “0”.

Let me know if it works for you.

-skb


#6

Hi, thanks for that. I understand what you’re saying but I’m not sure where I should add the condition. The image below shows my current interactions. Please could you show me?


#7

@jopsmith,

Sure, no problem… you need to double-click OnItemLoad to add the new case, then Add the Condition, then drag it up to the top. It should be above all the other cases in the list.

Note: When you drag it up to the top, you’ll need to switch the Case 0 back to an “If” case. When you drag a case above it, usually the case will switch over to an Else If case and you’ll need to switch it back.

Let me know if it works for you.

-skb


#8

Perfect, thanks! Works like a dream now :slight_smile:


#9

@JopSmith

Awesome! Glad it worked for you. :slight_smile:

-skb