What is the easiest and most accurate way to average feet/inches? - google-sheets

Using the format #'##, what would be the best way to average values using a formula?
For example: if I have the following values -
The average of these heights should return 5'01. What would be the best way to achieve this using a formula? Thank you!

try:
=INDEX(JOIN("'", TEXT({"", "0."}&SPLIT(AVERAGE(QUERY(QUERY(SPLIT(A1:A3, "'"),
"select Col1+Col2/12"), "offset 1", 0)), ".")*{1, 12}, {"0", "0#"})))

Given your post data, which runs A1:A3 (and I'm assuming further down than Row 3):
=ArrayFormula(INT(AVERAGE(FILTER({VALUE(REGEXEXTRACT(A:A,"\d+"))+VALUE(REGEXEXTRACT(A:A,"\d+$"))/12},A:A<>"")))&"'"&TEXT(ROUND(MOD(AVERAGE(FILTER({VALUE(REGEXEXTRACT(A:A,"\d+"))+VALUE(REGEXEXTRACT(A:A,"\d+$"))/12},A:A<>"")),1)*12),"00"))
In summary, REGEXEXTRACT is used to separate the left and right portions of the original data. VALUE converts them from strings to numbers. /12 and *12 do the conversion from inches to decimal and back to inches. The ampersand (&) symbols are used to concatenated the final INTeger portion, the feet symbol (') and the converted decimal-to-inches value. TEXT assures that the final result is in the format 00.

I've come up with a formula that might solve your problem but it is a bit long.
=ROUND(ARRAYFORMULA(AVERAGE((REGEXEXTRACT(A1:A3, "(\d)'\d+")*12)+REGEXEXTRACT(A1:A3, "\d'(\d+)")))/12)&"'"&MOD(ARRAYFORMULA(AVERAGE((REGEXEXTRACT(A1:A3, "(\d)'\d+")*12)+REGEXEXTRACT(A1:A3, "\d'(\d+)"))),12)
What the formula does is it calculates the values of A1:A3 into inches and gets the average before converting it again into feet'inches format. Please see result below.

Related

Google Sheets: Sum if value is round number

I'm sure there's a pretty simple solution, but I cant' get to it.
I'm trying to sum a list of numbers, but only the values that are round numbers/whole integers.
Eg column A:
1
1.5
3
2.4
2
sum of the whole numbers
1 + 3 + 2 = 6
Any hint?
Let's suppose your numbers list begins in A2 and runs downward (i.e., A2:A). You can use this:
=SUM(FILTER(A2:A,A2:A=INT(A2:A)))
In plain English, this reads as follows: "Sum only those numbers in A2:A where the original value is the same as the integer-only portion of that value."
Try:
=sumproduct((A1:A5)*(A1:A5=int(A1:A5)))
this will also work in Excel
use dot detection:
=INDEX(SUM(IF(REGEXMATCH(""&A:A, "\."),,A:A)))
Another solution, you can use SEARCH to search for the decimal point:
=SUM(A1:A)-SUM(FILTER(A1:A,SEARCH(".",TO_TEXT(A1:A))))
or =SUM(FILTER(A1:A,NOT(ISNUMBER(SEARCH(".",A1:A)))))
as JvdV mentioned in his comment.
Either try QUERY():
=SUM(QUERY(A:A,"where A matches '\d+'"))
Or FILTER():
=SUM(FILTER(A:A,MOD(A:A,1)=0))
Note: This 1st option makes use of the possibility to use a regular expression inside the "where" clause of QUERY(). Use =SUM(QUERY(A:A,"where A matches '-?\d+'")) if you want to account for positive and negative integers.

Formula that will skip one column when calculating SUM() or similar functions

I'd like to run a =SUM(A1:G1), but always skip one column, regardless if it has value or not.
In this case, it should calculate A1+C1+E1+G1.
Is there another function I could append to SUM() or other similar functions as SUM in order to skip one column?
Thank you!
Using the following method you can calculate any number of alternate columns, without the need of manual +
Suppose your data is in second row onwards, use this formula
=SUMPRODUCT(A2:G2, MOD(COLUMN(A2:G2),2))
Simply a sumproduct of cell values and a array of {1,0,1,0,1...}
Another slight variation
=SUMPRODUCT(A2:G2*ISODD(COLUMN(A2:G2)))
But if the even columns contain letters instead of numbers this will give an error, so you can use instead
=SUMPRODUCT(N(+A1:G1)*ISODD(COLUMN(A1:G1)))
Comparing #AnilGoyal's answer, this works as well
=SUMPRODUCT(A1:G1,--ISODD(COLUMN(A1:G1)))
You can use:
=SUM(INDEX(A1:G1,N(IF(1,{1,3,5,7}))))
Or with Excel O365:
=SUM(INDEX(A1:G1,{1,3,5,7}))
A bit more of a general solution:
=SUMPRODUCT(MOD(COLUMN(A1:G1),2)*A1:G1)
Or with Excel O365:
=SUM(MOD(COLUMN(A1:G1),2)*A1:G1)
Or even:
=SUM(INDEX(1:1,SEQUENCE(4,,1,2)))
Since you included Google-Sheets, I'll throw in an option using QUERY():
=SUM(QUERY(TRANSPOSE(1:1),"Select * skipping 2"))
Maybe a bit more verbose, but very understandable IMO.
Consider something of the format:
=SUM(A1:G1)-INDEX(A1:G1,2)
The 2 in the formula means remove the 2nd item in the part of the row. (so the 999 is dropped)
So the formula =SUM(BZ10:ZZ10)-INDEX(BZ10:ZZ10,2) drops CA10 from the sum, etc.(a similar formula can be constructed for columns)
google sheets:
=INDEX(MMULT(N(A1:H3), 1*ISODD(SEQUENCE(COLUMNS(A:H)))))
=INDEX(IF(ISODD(COLUMN(A:H)), TRANSPOSE(MMULT(TRANSPOSE(
IFERROR(A1:H3*ISODD(COLUMN(A:H)), 0)), 1^ROW(A1:A3))), ))

Using number formatting on a scientific number changes the value

I have a string which is eval_id = -8880305704784521238 in google sheet.
When I used split formula =SPLIT(A1,"=") it gives me result in scientific number
eval_id -8.88031E+18
But when I used number formatting it changes the value of the number.-8880305704784520000 which is not equal to the actual number -8880305704784521238.
How can I fix this issue.
Try this:
=REGEXEXTRACT(A1,"-*\d*.?\d+")
or as an array formula (specify the range):
=ARRAYFORMULA(REGEXEXTRACT(A1:A15,"-*\d*.?\d+"))

Split function treating dashes oddly

Why does =SPLIT("1,2-5,4", ",")
equal
1 42040 4
instead of
1 2-5 4 ?
I have all of the cells formatted at plain text.
Regextract should give you the desired output. Try:
=ArrayFormula(regexextract("1,2-5,4", {"^(\d+),",",(.+),",",(\d+)$"}))
To complement JPV's answer.
You can use:
=REGEXEXTRACT(A1,"(.*?),(.*?),(.*)")
which is "hard-coded" to splitting exactly 3 elements (as JPV's is). To give more flexibility, you can use something like:
=REGEXEXTRACT(A1&REPT(",",10),REPT("(.*?),",10))
which is limited to a maximum of 10 elements (that number can be changed to suit). However, it will output an array that is always that maximum number of elements long (padded out with blank cells). You could use QUERY or FILTER to filter out those blank cells - the formula will become a little convoluted.
Alternatively, you can "code" your string such that automatic date coercion is avoided, and then "uncode" it after the SPLIT:
=ArrayFormula(SUBSTITUTE(SPLIT(SUBSTITUTE(A1,"-","x"),","),"x","-"))
With 1,2-5,4 in a cell this can be split as required with Data > Split text into columns... .

Ignoring blanks in averageifs when data has negative numbers and zero

I have a formula that will take the data from the past 30 days (column A are dates, column F has the data which is always either blank or above 0).
=AVERAGEIFS(F3:F, A3:A,">"&TODAY()-30, F3:F, ">0")
I need another, similar formula to apply to column H, however H will have negative numbers and 0. I would have thought this would work but it is simply not ignoring the blanks and the average does not match when I do a regular average and manually select the non blanks.
=AVERAGEIFS(H3:H, A3:A,">"&TODAY()-30, H3:H, "<>''")
What am I missing?
Apparently, it's just:
=AVERAGEIFS(H3:H, A3:A,">"&TODAY()-30, H3:H, "<>")
That unfortunately wasn't very clear in the documentation.

Resources