why am I getting wrong values with countif statement? - google-sheets

When I use count the number of days each employee working in a given week I am getting the wrong values. I am expecting 4 for I90 and 4 for I91. I don't know why the results are off.

try:
=QUERY(C:C; "select C,count(C) where C is not null group by C label count(C)''")

If you're dragging down the formula, is the countif range C88:C101 in all cases? You may need to fix it with C$88:C$101 or use an arrayformula from cell I88 like this (deleting all values below):
=arrayformula(if(H88:H<>"",countif(C$88:C$101,H88:H),))

Related

How to use COUNTIFS with ARRAYFORMULA

I have this formula that checks for the 2nd(onwards) instance of duplicate using 2 columns. I want it to be automatically applied to new rows but can't seem to figure out how to use ARRAYFORMULA for COUNTIFS. Can anybody please help me convert this formula =COUNTIFS($K$2:$K2, $K2, $T$2:$T2, $T2)>1 to an arrayformula or something similar? Thanks!
MAP() function may be a good solution. Try-
=MAP($K$2:INDEX($K$2:$K,COUNTA($K$2:$K)),$T$2:INDEX($T$2:$T,COUNTA($K$2:$K)),LAMBDA(x,y,COUNTIFS($K$2:$K,x,$T$2:$T,y)>1))
K2:INDEX(K2:K,COUNTA(K2:K)) will return a array of range from K2 to next non empty cell of K column.
Same T2:INDEX(T2:T,COUNTA(K2:K)) will return a array of range from T column still base on K column last non empty cell.
Edit: As per comment, try below formula-
=INDEX(MAP(A2:INDEX(A2:A,COUNTA(A2:A)),C2:INDEX(C2:C,COUNTA(A2:A)),LAMBDA(x,y,COUNTIFS(A2:A,x,C2:C,y,ROW(A2:A),"<="&ROW(x))>1)))
Change ranges for your sheet.

Google Sheets query to get sum of two columns

I am trying to get sum of two columns using Query function and am getting perfect result when all the two columns have value, however, if any of the column is not having a value than the result will be blank. In such a case I want to reflect the value of the second column having data. Check the below image:
Formula used =QUERY(A2:C,"select A,B+C label B+C ''",0)
Sharing the link of the sheet too for reference.
https://docs.google.com/spreadsheets/d/1TID_7m6MTNviLkU0dlPoCDyA8Uv9Iann2WtCYL9CJQo/edit#gid=0
Any help on above will be appreciated.
I had also searched community for similar issue but not found the exact match.
Give a try on below formula-
=QUERY({A2:A,INDEX(IF(B2:C="",0,B2:C))},"select Col1,Col2+Col3 where Col1 is not null label Col2+Col3 ''")
Here IF(B2:C="",0,B2:C) will convert null cells to zero 0 values.
try:
=INDEX({A2:A4, B2:B4+C2:C4})

Count number of rows where the minimum of multiple columns is less than a specific number

I am trying to find a way to do this in Google Sheets, but couldn't really figure out the syntax - not quite sure whether I should be starting with COUNTIF, ARRAYFORMULA, or something else.
e.g.
How would I have a formula that would count the number of rows, if the minimum for each row between columns A-C is less than 2? In this case, the result should be 3.
Use QUERY:
=IFERROR(QUERY(A1:C5,"select COUNT(A) where A<2 or B<2 or C<2 label COUNT(A) ''", 0),0)
Given your sample data setup, this should work:
=COUNTA(FILTER(A:A,(A:A<2)+(B:B<2)+(C:C<2)))

Google Sheets Query Coalesce?

is there any query syntax that woks like coalesce in google sheets?
if i have a source like pict below
the result i want is only getting id and time if status is true, but the time is only exist in one col either in check column or report column
so the result would be like this...
I tired this but doesn't work
=QUERY(A1:D4, "SELECT A, COALESCE(B, C) WHERE D = TRUE")
any ideas or workarounds?
Thanks
try:
=ARRAYFORMULA(IFERROR(SPLIT(FLATTEN(QUERY(TRANSPOSE(
ARRAY_CONSTRAIN(IF(D2:D=TRUE, {A2:A, IF(B2:C="",,"×"&B2:C), D2:D}, ), 9^9,
COLUMNS(A:C))),, 9^9)), "×")))
A very short one just for the special case of 2 columns where you know that only one of them is populated and they are dates:
=ArrayFormula(to_date(if(D2:D,B2:B+C2:C,)))
Maybe the simplest formula which behaves like coalesce would be
=iferror(if(D2,hlookup(9^9,B2:C2,1,true),))
It's just a pull-down formula but will pick up the first non-blank column from a range of columns containing numbers or dates. If the columns are all blank, it returns blank.
You can take advantage of the either or situation and concatenate the 2 columns.
=filter({A2:A,concat(B2:B,C2:C)},D2:D)
Also see local array and filter
Add a column after Status call it Time (column E), whereas each formula follows this format (assuming your table starts at A3:E)
=if(A4="","",if(B4<>"",B4,C4))
Now query A3:E like so,
=query(A3:E,"Select A,E where D=TRUE")
you can use something like this:
=QUERY(transpose(B1:H1),"Select Col1 where Col1 is not null limit 1",0)
This transposes the row into a column, queries all non-null values from that column, and then set limit 1 to return the first value. So essentially you are selecting the leftmost non-empty value from your row.
I can't take full credit for this, I must have gotten it somewhere else... but it's in one of my sheets.

Using Countifs to count number of values in a range getting an Array arguments to COUNTIFS are of different size

Working on a Google Spreadsheet seems to be behaving strangely.
I'm getting the error Array arguments to COUNTIFS are of different size.
this formula works fine for me.
=COUNTIFS(Bookings!R:R,"<>",Bookings!AI:AI,month(A:A),Bookings!AJ:AJ,year(A:A))
but this one gives the error:
=COUNTIFS(Bookings!R:R,"<>", month(Bookings!D:D), month(A:A), year(Bookings!D:D), year(A:A))
I have a date in the D column while in the column AI I have a month 12 and in AJ I have a year like 2019.
Would love to get some insight on how to solve this.
let the Bookings sheet be:
then you need to do:
=ARRAYFORMULA(IF(LEN(A2:A), COUNTIFS(Bookings!R2:R, "<>",
MONTH(Bookings!D2:D), MONTH(A2:A),
YEAR(Bookings!D2:D), YEAR(A2:A)), ))

Resources