I'm trying to sum a range of values, but the values in my range comes from a formula resulting in string values (string user input, number extracted with left()). This makes =sum(A:A) not work.
What I would like to do is something along the lines of =sum(value(A:A)), but I need value() to apply to each cell before they are all summed up.
I would like a general solution applicable to any preprocessing formula.
Try this one:
=sum(ARRAYFORMULA(--A:A))
BTW, you could also double minus each number before summing: = --left(B1) will give the number. If A:A contains text, then use =sum(IFERROR(ARRAYFORMULA(--A:A)))
Related
I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).
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+"))
I'd like to apply a conditional formatting rule to a named range. Is that even possible? How do I do that? When trying to enter the Name of the Range to the Field where you set up the range the rule applies to it won't accept my input.
Also with INDIRECT it does not work:
this is not possible in Google Sheets
for the custom formula you need to wrap it into INDIRECT formula like:
I think it is not possible, it is not documented in official docs.
Range names:
Can contain only letters, numbers, and underscores.
Can't start with a number, or the words "true" or "false."
Can't contain any spaces or punctuation.
Must be 1–250 characters.
Can't be in either A1 or R1C1 syntax. For example, you might get an error if you give your range a name like "A1:B2" or "R1C1:R2C2."
The following works for my specific use case, where the named range is an "unknown" number of rows.
In this case, A1 is a column heading, and is not part of the named range.
A2:A5 is currently assigned to the named range, CitationType.
Conditional formatting is applied to A1:A based on the formula:
=and(row(A1)>1,row(A1)<=1+rows(indirect("CitationType")))
I did not find an easy way (without scripting) to get the address details of a named range, allowing for "arbitrary" usage in conditional formatting.
For custom formulas in Sheets conditional formatting, the formula usually accesses a column value in the first row of the format range. Named range values can be used in custom formulas using INDIRECT function.
example from my case ... a list of "brackets" in a tournament. Bracket rows are coloured depending on what bracket the row is for (e.g. brackets 1-10), that value is in the E column.
The formula specifies the appropriate column in the first row of the range (row is relative as conditional formatting iterates over the range). Since my range is B2:G1005, the formula references cell $E2 (the bracket ID) and compares it to the bracket id stored in a named-range location (BID_1), so custom formula is:
=$E2=INDIRECT("BID_1")
(if bracket matches the ID assigned to bracket 1 -- colour the cells grey with bolded black text).
Screenshot of conditional formatting using a named range
I have a google sheet which looks like this :
The formula for cell M3 is =COUNTA(UNIQUE(B3:L3)) which outputs the 01/10/00. However the cell B18 is =COUNTA(UNIQUE(B3:B17)) and its output is 15
I wanted to get this count of unique values in the range using the formula but can't figure out the cause of difference of the outputs. Also, the count of unique values in a row should be 11 which is not really reflected in M3 and any changes are not changing the value of the output either.
there is a combo formula for that called COUNTUNIQUE
=COUNTUNIQUE(B3:L3)
The formatting of M3 is probably set to Date and that's converting your number into that date view. Additionally, if you're getting a higher number than you expect in general, double check for trailing spaces that can trick the unique() function.
I was looking a the formula for cumulative sum using arrayformula:
ARRAYFORMULA(SUMIF(ROW(A1:A10), "<=" & ROW(A1:A10), B1:B10))
I used arrayformulas before, but mostly for simple arithmetic, so I am trying to wrap my head around this.
The reason it is unclear for me is that I don't know what the rules are for ARRAYFORMULA to use the range, or to use the scalar value.
If I tabulate it it becomes something like this:
row 1: SUMIF(ROW(A1:A10), "<=" & ROW(A1), B1:B10))
row 2: SUMIF(ROW(A1:A10), "<=" & ROW(A2), B1:B10))
...
row n: SUMIF(ROW(A1:A10), "<=" & ROW(An), B1:B10))
But that doesn't actually work because ROW doesn't work like that if not used in an ARRAYFORMULA, according to the docs:
ROW([cell_reference])
if cell_reference is a range more than one cell wide and the formula is not used as an array formula, only the numeric value of the first row in cell_reference is returned.
Looking at the syntax for SUMIF it is:
SUMIF(range, criterion, [sumrange]).
Do I understand it correctly that the rules for ARRAYFORMULA are:
If a function parameter inside ARRAYFORMULA is expected to be a scalar (criterion in the examle) and a range is given it will expand in the cells below iterating this range
If a function parameter inside ARRAYFORMULA is expected to be a range (range and sumrange) and a range is given it will pass on the range to the formula
So, the question is:
What is exactly happening row by row with the formula pasted above and how does ROW behave in this? ROW is 'aware' that it is being used in an arrayformula and behaves differently?
It's not about the ROW. Its more about the & and the strings used. Used inside a arrayformula, it creates series(a array) of strings. So, "<="&ROW(A1:A10) becomes "<1","<2" and so on. Criterion argument of SUMIF expects a string and only a single string. Given the array, it creates a array of results for each criterion, the Range argument being the same for each criterion. Also, SUMIF already expects array for the range argument.