Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Nov 14, 2022 05:52 AM
From a look-up field array, I’m extracting a duration h:mm, which I’m trying to convert to a duration field.
The time comes out alright in a human readable format, e.g. 2:59, 4:24, 6:00, but I’m struggling to convert the string into a duration formatted field via formula.
I tried using a few formula
Solved! Go to Solution.
Nov 22, 2022 05:36 AM
Thanks, I suppose you refer to this setup?
In the given case, I always want to get the first value in the array, but there’s no logical order as in min/max value, which I think was used to determine the first/last dates?
Using the search I came across this post and am using this formula to get the first item:
LEFT( ARRAYJOIN( {my_array} )&',', FIND( ',', {my_array}&',' )-1 )
Nov 22, 2022 05:54 AM
Yes, that is one system. You could use a created time field to identify the first date, which is probably the first linked record. But if there really is no logical order to the durations, why does the first one even matter.
There are many ways to do thing in code. One way is to get the first item as a string, parse the hours and minutes separately, use VALUE()
to convert the individual hours and minutes to numbers. Then multiply / add to get seconds, which you then format as a duration. But I wouldn’t do it that way. I would find out out to uniquely identify the one duration I wanted and use a conditional rollup.
Nov 22, 2022 11:45 PM
The order is user arranged, dragging the linked record up or down.
That’s probably going to much into detail… but I’m a dealing with a junction table called Itinerary, where Trips and Days are related with each other.
Other than adding yet another junction table to determine the order of activities related to a day, which I was trying to avoid to reduce complexity for the users, I cannot come up with ways to use a conditional rollup.
Nov 24, 2022 12:00 PM
Okay. Thank you for the explanation.
This formula assumes that the original field is a duration field. Be sure to set the formatting options for the formula field to display the number as a duration.
IF(
{Time},
VALUE(
REGEX_EXTRACT(
ARRAYJOIN(Time, ","),
"\\d+"
)
)
)
If you want a formula for {Time2} …
IF(
COUNT({Time}) >= 2,
VALUE(
REGEX_REPLACE(
ARRAYJOIN(Time, ","),
"(\\d+,)(\\d+).*",
"$2"
)
)
)
{Time3}
IF(
COUNT({Time}) >= 3,
VALUE(
REGEX_REPLACE(
ARRAYJOIN(Time, ","),
"(\\d+,){2}(\\d+).*",
"$2"
)
)
)
{Time4}
IF(
COUNT({Time}) >= 4,
VALUE(
REGEX_REPLACE(
ARRAYJOIN(Time, ","),
"(\\d+,){3}(\\d+).*",
"$2"
)
)
)
Dec 05, 2022 04:47 AM
Thanks for that! I didn't realize that regex maintains the original field type/formatting.