Google spreadsheets - how to handle duration: store and use in calculations? - google-sheets

I've got a lot of "duration" values - basically a race duration - in a format m:ss.millis [4:03.810 for example].
Currently GS handles it as text, but I would like to use those values for comparison and create some statistics.
Is this possible? I have read this: How to format a duration as HH:mm in the new Google sheets but even though I have created a custom formats like:
or
but neither with one nor with another I cannot use those values for calculations. GS always complains about the values beeing stored as text.
I guess I'm just doing something wrong, but I definitely need to be able to provide values in this format and be able to use them in calculations.
How can I do that?

I regret that Duration seems to be a useless abomination and Sheets appears to offer no relatively easy way to convert text representation to values. Pending a better answer I suggest you convert all your durations as below:
=(left(A1,find(":",A1)-1)+right(A1,6)/60)/1440
format as Number:
mm:ss.000
and then apply your formulae.
(Change , to ; if required by your locale.)
A shorter formula might be used to cajole TIMEVALUE to work by including an hour value of 0:
=TIMEVALUE("00:"&A1)
A happy coincidence brought me back here because only very recently have I found that Google Sheets does offer a way to convert Text to Number (or I was having another aberration when I claimed otherwise). However, this still seems not to apply to Duration. Maybe there is yet hope though.

Related

Why is this Google Sheets Concatenate Formula giving me weird results?

I'm trying to use Google Sheets to concatenate a bit of data. It works 90% of the time, however on certain numbers, I get an odd result. I have to copy the result of this data and paste it into a financial program in a specific format and am using the concatenate formula to do this. The format the program requires is that each field be separated by one period, even if it is a dollar amount as the program will automatically move the decimal point two places to the left while it is evaluating the information. The issue is that on some numbers the formula adds two periods between the fields, which stops the evaluation of the data in our financial program.
Here is a screenshot including the formula
You can see that it works with most numbers in the amount column, but with two of the amounts and several others, it adds two periods after the amount.
Would you please take a look at this and see if you can help me find the issue?
Thank you!!!!
Looks like it's an existing floating point calculation error in Google Sheets, the multiplication by 100 did not return exact value for certain numbers but with extra very small decimal. That's why there's an additional period on the result.
As a workaround, use ROUND() upon multiplying by 100 to "snap" it to an integer.
Sample:
References:
Floating Point Calculation Error
use just:
=B2&"."&ROUND(C2*100)&"."&D2

Convert text to number in Google Sheets

I'm reading currency values from a website and I'd like to do some calculations with these numbers. They come in this format:
$7,821.24
Here's an example file:
https://docs.google.com/spreadsheets/d/1vHEH_m16KXcDh7hY_BVG9lur1huFjWOnx5bWtgrdGdA/edit?usp=sharing
Now for some reason neither VALUE() and TO_PURE_NUMBER work for me (Can't parse to numberic value, telling me it's a text value).
My guess is that the comma and the $-sign confuse the formula, is there anything I can do to format this correctly? The dollar sign always appears in the values but the comma only appears separating thousands of values.
I just started using Sheets for this so I absolutely have no clue. Would really appreciate if someone could help me out.
Thanks for your time!
Issue:
It's a locale problem. The value coming from IMPORTXML is formatted as in United States locale, so your spreadsheet (which uses a different format) cannot convert it.
Solution #1. Changing locale:
If the spreadsheet locale is changed to United States or others with the same format (via selecting File > Spreadsheet settings and setting the mentioned locale), the retrieved value will be a number, and you can work with it without using any other formula.
Solution #2. Formula:
If changing the locale is not an option, one possible way to convert the value to a valid number in your locale is the following formula:
=SUBSTITUTE(SUBSTITUTE(RIGHT(A2;LEN(A2)-1);",";"");".";",")
Changing locale didn't work in my case. But I was able to split the number which google sheet isn't detecting as a real number. So split it with "," and "." and any currency sign you may have, and then combine individual values for desired output

How can I use the OFFSET() formula with a range of values?

EDIT: Disclaimer about the XY problem: The actual, concrete problem I'm trying to solve is: How can I make "recursive" (is that the right term here?) formulas that use infinite ranges in Google Spreadsheets/Excel? The solution I'm working with involves the OFFSET() formula. I'm asking this question because I'd like to get an extensible understanding of the way formulas use and implement ranges, especially infinite ranges.
I'm working in Google Spreadsheets and trying to create ArrayFormulas that will automatically expand without needing to use the fill handle as new data is added in the requisite columns.
To do this, I want to use infinite ranges such as A2:A when I do calculations so that no matter how much data is added, I'll never have to drag-fill any data or formulas and I can just let the spreadsheet iterate and do the work.
I'm running into a problem, though, when I try to use these infinite ranges with the OFFSET() formula. What I'm trying to do is have each cell in the range pull values from a couple of the cells next to it (thus the offset), do a simple calculation with those values, and make that the new cell value. But because the formula interprets the instruction as attempting to offset an entire (infinite) range of values, it returns a #REF! error. Here's a shared example sheet that demonstrates what I'm trying to do.
https://docs.google.com/spreadsheets/d/1V3ldSBoCrzyVWcn66wFBkDOmxt6iuYgtiU_H4KQ6J14/
If for some reason you can't see the formulas, the formulas I'm using are:
C3 =ArrayFormula(Offset(C3:C, 0, -1) - Offset(C3:C, -1, -1))
F4 =Arrayformula(Offset(F3:F, 0, -1) + Offset(F3:F, -1, 0))
Both of these return a #REF! error. C3's alt-text reads: "Error: Result was not automatically expanded, please insert more rows (1)." F3's alt-text reads: "Error: Circular dependency detected."
I'm decently confident why these don't work - you're apparently not allowed to use and refer to ranges this way. I don't, however, know how to fix this.
The two use-cases in the spreadsheet are essentially the same thing, backwards. Chances are if I can figure out one I can reverse-engineer it to work for the other one, but I've had no luck so far.
I've Googled around a lot and while I've never found anything that solves this problem, a lot of similar problems seem to be solved by using the INDIRECT() function. I can't understand how this would apply here, though, that function seems to be strictly for parsing values dynamically from cells with variable input.
(I should probably mention that this data is on a back end sheet and it's getting pulled on another sheet to display some charts on the front end. I wouldn't ask a question here if this data was the only thing involved.)
Any help or a step in the right direction would be appreciated.
If I'm understanding your question, one way to make an offset function expand automatically is to attach a count function, eg. in excel
=offset(C2,,,counta(C:C))
However, this will give you a circular reference error. To address this issue, this is one solution that I have used:
"OFFSET(C3,,,MATCH(9.99999999999999E+307,OFFSET(C3,,,ROWS(C:C)-ROW(C3))))"
This function passes an array based on the last number cell in the column. And for it to be used properly, it needs to be wrapped in a function that can handle arrays, like SUM().

How do I increment a string value in Google Spreadsheet?

Long time Lurker reporting in! My issue is I'm not sure how to increment an Item no. It follows this format : LK0001 the row below it will be LK0002, below that LK0003 and so on I'm not sure how to automate this process, as you can tell I'm fairly new to google spreadsheets Sorry if it's already answered , I just can't seem to find it! Thanks!
Weej
First of all, I would suggest using the following ID build-up:
LK1000
This way characters (LK) can be separated from integers (1000). Otherwise you would face the problem, that if you increase LK0009 by 1 it becomes LK00010 and not LK0010
ID's need to be "hard coded", meaning =CONCAT or =A1+1 or =MAX(A:A)+1 are not allowed.
Either go by typing LK+max. number and use the ID as a text or go for the integers and use CONCAT when needed.
If you chose to go with the integers, you can easily increment them by doing this:
and then dragging it downwards, yielding:
I've prepared an example for you: How do I increment a string value in Google Spreadsheet?

Parsing and validating arbitrary date formats in ruby (on rails)

I have a requirement to handle custom date formats in an existing app. The idea is that the users have to do with multiple formats from outside sources they have very little control over. We will need to be able to take the format and both validate Dates against it, as well as parse strings specifically in that format. The other thing is that these can be completely arbitrary, like JA == January, FE == February, etc...
to my understanding, chronic only handles parsing (and does it in a more magical way then I can use), and enter code here DateTime#strptime comes close, but doesn't really handle the whole two character month scenario, even with custom formatters. The 'nuclear' option is to write in custom support for edge cases like this, but I would prefer to use a library if something like this exists.
I don't think something that handles all these problems exists if the format is really very arbitrary. It would probably be easiest to "mold" your input into a form that can be handled by Date.parse, Date.strptime, or another existing tool, even though that could mean quite a bit of work.
How many different formats are we talking about? Do any of them conflict? It seems like you could just gsub like so: input_string.gsub(/\bJA\b/i, 'January'). Is this part of an import routine, or are the users going to be typing in dates in different formats?
There's a related question here: Parse Italian Date with Ruby

Resources