x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 845

# field calculation that rounds up to a "nearest value"

In our invoice/billing system, our technicians clock in and out of each work ticket. We have a field that calculates the "time billed" based on these time ins and outs (there can be up to three ins and outs on each ticket).

Currently our method is as listed in the code snippet. This field calculates to the minute, so if we clock in at 10:00 and clock out at 10:08 it calculates 8 minutes. A change in our pricing structure has been made so that there is a minimum of 15 minutes for service calls (and time is billed in 15 minute increments).

We would like to change this field so that for each time in/out instance, it rounds UP to the nearest 15 minute increment (IE 15, 30, 45, 60, etc..). It would round for each time in/out instance, then add those (up to) three values for the "total time".

Also, should we create a new field for this? We don't want to recalculate any of the existing data as that would change values on outstanding invoices. Currently it is set in storage options to "recalculate as needed".

Thanks!
``````(BILLING_ITEMS::TIME_OUT_1 - BILLING_ITEMS::TIME_IN_1) + (BILLING_ITEMS::TIME_OUT_2 - BILLING_ITEMS::TIME_IN_2) + (BILLING_ITEMS::TIME_OUT_3 - BILLING_ITEMS::TIME_IN_3)
``````
0
Eroots
• 2
1 Solution

Commented:
Here's a simple formula that will "round up" to the next 15.

Ceiling( NumberOfMinutes / 15) * 15

If you enter any number of minutes from 1 to 15, it returns 15. If you enter 16, it returns 30, and so forth.

With regard to your history, you definitely don't want to change historical data, so creating a new field for this purpose might be a good idea, but it might also complicate things if you have lots of references to the old field.

One way you could handle that would be to make your calculation conditional on the invoice date. Apply the old calculation for records created before a specific cut-off date, and the new one for any created after that date.

If ( InvoiceDate  >=  "5/1/2008" ;
Ceiling( NumberOfMinutes / 15) * 15;
NumberOfMinutes
)

This formula applies the rounding up function to any records with a date of 5/1/08 or later, and simply returns the original number for earlier dates.
0

Author Commented:
Thanks for introducing the ceiling function, but it took me a while to figure out the whole calculation as it applies to minutes. Here is what I came up with:

(Ceiling ((( Hour ( BILLABLE_TIME )*60)+Minute ( BILLABLE_TIME )) / 15 ) * 15) * 60
0

Commented:
Hmm, you didn't mention anything about needing to calculate the time difference in your original question, and said you'd already done that before, so I assumed you already knew how.

The formula you used works, but there's a simpler way.

FileMaker times are stored as numbers of seconds internally. They are displayed with formatting to show hours, minutes, etc, but internally it's just a number of seconds.

That means you can do normal math with time values. If you subtract Time A from Time B, you get the difference between the two times in seconds.

Assuming BILLABLE_TIME = END_TIME - START_TIME then all you need to do is

Ceiling(  BILLABLE_TIME / 60 / 15 ) * 15

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.