I am trying to create a formula that will provide the standard deviation based on two conditions - I am able to add the condition where equal to a cell value (T2), but I would like to also add where L3:L2987 <>0. I continue to get parsing errors....here is the original formula (google sheet)
=iferror(arrayformula(STDEV.S(if($D$3:$D$2978=$T3,$L$3:$L$2978))),"--")
Any suggestions would be great.
You can try this:
=IF(IFERROR(MATCH(T3,D3:D2978,0),0)*IFERROR(MATCH(0,L3:L2987,0)*0,1),STDEV.S(L3:L2978),"--")
To explain the condition:
IFERROR(MATCH(T3,D3:D2978,0),0)
MATCH searches D3:D2978 for a value equal to T3 and returns N/A if value is not found. IFERROR will return 0 if MATCH returns N/A.
Same principle with IFERROR(MATCH(0,L3:L2987,0)*0,1), but the multiply by 0 will ensure that FALSE (0) is returned when a 0 was found on the range. It will return 1 if MATCH returns N/A.
Multiply works as an AND operator.
If both conditions are non-zero, return STDEV.S(L3:L2978), else --.
Sample Output:
try:
=IFERROR(STDEV.S(FILTER(L3:L, L3:L<>0, D3:D=O3)), "--")
arrayformula of stdev.s is nowdays possible:
=BYROW(UNIQUE(FILTER(D3:D, D3:D<>"")),
LAMBDA(xx, IFERROR(STDEV.S(FILTER(L3:L, L3:L<>0, D3:D=xx)), "--")))
Related
What I'm trying to do is find the name of the person who is ranked number 1 in the table shown below. I have tried =LOOKUP and =VLOOKUP but I get an error saying that a result can't be found, even though it's obviously there. I assume that I'm either using the wrong function or just not using it right.
I tried =VLOOKUP(1;D2:H19;1) and =LOOKUP(1;D2:H19;1) but neither seems to work.
Answer
The following formula should produce the behaviour you desire:
=INDEX(D2:D,MATCH(1,H2:H,0))
Explanation
=VLOOKUP can only be used to find values to the right of a search key. To find values to the left of a search key, use a combination of =INDEX and =MATCH.
The =MATCH function searches a specified range for a specified value and returns the relative position of the value in that range. In this case, the value to search for is 1, the range to search through is H2:H, and the 0 at the end specifies that the range is not sorted in any way.
The =INDEX function returns the contents of a cell within a range having a specified row and column offset. In this case, the range is D2:D, and the row is whichever row is returned by =MATCH. =INDEX could take a third argument if it was desired to specify a row offset as well, but that is not necessary here.
Functions used:
=INDEX
=MATCH
You sort your ascending order based on rank then return your desired data using INDEX() function. Try-
=INDEX(SORT(D2:H500,5,1),1,1)
=vlookup(1,{H2:H19, D2:D19},2)
Since vlookup only searches the 1st column of the input range, to use it, you need to flip the columns by composing a local array: {H2:H19, D2:D19}.
{} means concatenation. , in it means horizontal concatenation. With that, the rank column is now the 1st column in the input of vlookup and now vlookup works.
With our local array, the 2nd column are the names and therefore index should be 2.
Also note the use of comma to separate function inputs.
your VLOOKUP formula should look like:
=VLOOKUP(1, {H2:H19, D2:D19}, 2, 0)
also try just:
=FILTER(D:D; H:H=1)
or:
=SORTN(D:D; 1; 1; H:H; 1)
You can use query (usefull in case of ex aequo)
=query(D2:H,"select D where H=1",0)
I am currently trying to make a sequence number generator in Google Sheets, and everything was going smoothly.
However, in the final steps, I noticed that one of my functions was returning the wrong value.
As you can see in C9, it returns the AMS20-00001 value despite BBAS2 is not present in A12:A13.
I noticed this happened with some of my previous sheets before this, and it got me wondering what causes this? Shouldn't it return as #N/A or #ERROR instead?
I would be glad if someone could give me an explanation of why this happens as well as what can I do to fix it.
Applies to Google Sheets and Microsoft Excel
There are three arguments in MATCH
Lookup value
Lookup array
Match type
MATCH(Lookup Value, Lookup Array, [Match Type])
Match type is optional and accepts one of three values
1 = exact or next smallest (default)
0 = exact match
-1 = exact or next largest
You've omitted the match type in your formula...
MATCH(A9,$A$12:$A$13)
This is the same as using the the default match type...
MATCH(A9,$A$12:$A$13,1)
The exact match was not found so your formula returned the nearest value that is less than the lookup value
Using 0 forces the exact match
MATCH(A9,$A$12:$A$13,0)
In your example, this results in the expected error
=INDEX($E$12:$E$13,MATCH(A9,$A$12:$A$13,0))
use vlookup:
=ARRAYFORMULA(IFNA(VLOOKUP(A8:A10, A12:E, 5, 0)))
In Google Sheets, when using ArrayFormula with AND formula, I don't get the results as it should be.
A
B
6
7
In C1 I put formula as: =and(A1>5,B1>6) then I get True. If in D1 I put formula as: =ArrayFormula(and(A1:A>5,B1:B>6)) I get the results as False.
Here are my two questions:
Why is ArrayFormula not repeated for all cells in the column?
Why do I get true without ArrayFormula and False with Arrayformula?
AND doesn't work that way with Array formulae because it ANDs the whole array together in the top left cell, regardless of number of dimensions.
I.e. it checks if "">"" which is FALSE, ANDed with anything it will return FALSE for the top left cell, that result is carried down.
You can use multiplication of truth values to create ANDing that works with ARRAYFORMULA like this:
=ArrayFormula((A1:A>1)*(B1:B>6) = 1)
The OR equivalent would obviously be
=ArrayFormula((A1:A>1)+(B1:B>6) > 0)
Take this formula for instance:
=ARRAYFORMULA(IF(ISNUMBER(G3:G),IF(AND( G3:G>=7.5,G3:G<=8),"Full Day",IF(AND(G3:G>8,G3:G<24) ,"Full Day+",IF(AND(G3<7.5,G3>=4),"Half Day",IF(G3<4,"Short Leave",)))),))
Since you use the ARRAYFORMULA function you should use * instead of the AND function.
=ARRAYFORMULA(IF(ISNUMBER(A3:A),IF((A3:A>=7.5)*(A3:A<=8),"Full Day",IF((A3:A>8)*(A3:A<24) ,"Full Day+",IF((A3<7.5)*(A3>=4),"Half Day",IF(A3<4,"Short Leave",)))),))
When using the ARRAYFORMULA function you should use * instead of the AND function and + instead of the OR function.
Explanation
I don't recall an official site about this right now. In any case.
Point 1
Within an arrayformula, AND gives a single value. Not an array of TRUE/FALSE.
Point 2
You must also remember that in "math language", TRUE=1 and FALSE=0
Meaning
+----------+--------+
| Formula | Result |
+----------+--------+
| =TRUE+2 | 3 |
| =FALSE+2 | 2 |
+----------+--------+
As you can see one can interchange between boolean TRUE/FALSE and 1/0 numbers.
Point 3
About the AND function
The AND function returns true if all the provided arguments are logically true and false if any of the provided arguments are logically false.
Putting it all together
In an arrayformula, instead of using AND/OR when making comparisons, we take advantage of the above information.
So, the "multiplication" (A3:A>=7.5)*(A3:A<=8) will return 1 (meaning TRUE) only if both sides return TRUE. All other conditions return 0 (meaning FALSE).
This is the exact behaviour of the AND function and does work in an ARRAYFORMULA.
About the OR function
The OR function returns true if any of the provided arguments are logically true and false if all of the provided arguments are logically false.
The same logic is applied within the arrayformula, when using + ("addition") instead of the OR function.
AND doesn't go with an Arrayformula. However, there is an interesting way to use AND and OR operators without really using them.
While using arrayformula, in order to do an AND function you must multiply the 2 conditions, for example
=arrayformula(if((condition1)*(condition2), value if true, value if false))
Similarly using OR functions is identical EXCEPT instead of a "*" Symbol you would ADD the 2 conditions.
=arrayformula(if((condition1)+(condition2), value if true, value if false))
Why is ArrayFormula not repeated for all cells in the column?
As addressed in previous answers,
AND, ANDs the whole array, without regarding dimensions. But, given the recent updates in spreadsheets, using AND respecting dimensions, is now possible. If you want AND, by row, you can use BYROW:
=BYROW(
A2:B4,
LAMBDA(
row,
AND(INDEX(row,0,1)>5,INDEX(row,0,2)>6))
)
Here, INDEX is used to access the first column and second column of every row. If you don't want to use INDEX, Another alternative is MAP , which provides a MAP of every argument before LAMBDA:
=MAP(A2:A4, B2:B4, LAMBDA(a,b,AND(a>5,b>6)))
A
B
MAP
BYROW
6
7
TRUE
TRUE
8
1
FALSE
FALSE
9
7
TRUE
TRUE
I've a column of sample data where each cell is either blank or (3 alpha chars, 1 white space, 1 digit). For example:
I need to check if the cell begins with "GTR" or "DBT", then return the number, and sum the return of the column. I'm using the formula below:
=ARRAYFORMULA(sum(IF(OR(left(A1:A10,3)="GTR",left(A1:A10,3)="DBT"),VALUE(right(A1:A10,1)),0)))
The problem is that instead of returning 20, it returns 52.
In fact it appears to return the last char of any cell in the range. (eg. if "A5" has a value of 'someText' the formula returns an error because value() can't parse 't' into a number.
I'd like to know if anyone can tell me how to solve this problem, or if there's something wrong with my formula?
Here's an example of this problem in a Google Sheet:
https://docs.google.com/spreadsheets/d/1XNVUWhI43UW2ABrja8rmplmxhhkSu-je45F-9F_3GQM/edit#gid=0
Thanks,
Onji
The ArrayFormula plus OR will evaluate to TRUE if any of the cells in the range is in the codition, to overcome this remove the OR, and add an IF for every condition, as such:
=ARRAYFORMULA(sum(IF(left(A1:A10;3)="GTR";VALUE(right(A1:A10;1));0);IF(left(A1:A10;3)="DBT";VALUE(right(A1:A10;1));0)))
In addition to the solution of Kriggs, this formula should also work:
=ArrayFormula(sum(if(regexmatch(B3:B12, "GTR|DBT")=TRUE, right(B3:B12)+0,)))
I have a column with average(K23:M23) that starts out with #DIV/0! when the K23 through M23 cells are empty. Preferably I'd like to only do the average of cells that contain non-zero, non-blank values. I think it's possible using the query command:
https://docs.google.com/support/bin/answer.py?hl=en&answer=159999
But their example doesn't help me.
Wrap your formula with IFERROR.
=IFERROR(yourformula)
You can use an IF statement to check the referenced cell(s) and return one result for zero or blank, and otherwise return your formula result.
A simple example:
=IF(B1=0;"";A1/B1)
This would return an empty string if the divisor B1 is blank or zero; otherwise it returns the result of dividing A1 by B1.
In your case of running an average, you could check to see whether or not your data set has a value:
=IF(SUM(K23:M23)=0;"";AVERAGE(K23:M23))
If there is nothing entered, or only zeros, it returns an empty string; if one or more values are present, you get the average.
Wrapping the existing formula in IFERROR will not achieve:
the average of cells that contain non-zero, non-blank values.
I suggest trying:
=if(ArrayFormula(isnumber(K23:M23)),AVERAGEIF(K23:M23,"<>0"),"")
Since you are explicitly also asking to handle columns that haven't yet been filled out, and I assume also don't want to mess with them if they have a word instead of a number, you might consider this:
=If(IsNumber(K23), If(K23 > 0, ........., 0), 0)
This just says... If K23 is a number; And if that number is greater than zero; Then do something ......... Otherwise, return zero.
In ........., you might put your division equation there, such as A1/K23, and you can rest assured that K23 is a number which is greater than zero.
Check if the column has text format. Apply number formatting to the cells you're using in the average function.