How does COUNTA function works (google spreesheet)? - google-sheets

In a google spreadsheet I have the columns A and B populated with some data, then I have this formula to count the values in A if B=1:
=COUNTA(FILTER(A:A;B:B=1))
Problem is that the formula is counting 1 match even if there is no value matching the criteria.
This is the spreadsheet: https://docs.google.com/spreadsheet/ccc?key=0Ak9RViY8FJE5dF9PN3F2ZVFsenk3TG1LZkZjS0d4MHc#gid=0

Thats because the filter results in Error - showing the count 1 which is error...please try
=COUNTA(IFERROR(FILTER(A1:A3,B1:B3=1),""))

The error is being counted and the other result replaces the error with "" which would also return 1. If you want an empty filter result to return zero simply omit the second argument...
=COUNTA(IFERROR(FILTER(A1:A3,B1:B3=1)))

Related

Filter function creates empty rows

My understanding of the google sheets filter function is that it should limit the results to an array where the conditions are satisfied but I noticed this oddity:
Here is the sheet: https://docs.google.com/spreadsheets/d/1RL9cE6CYcpdNdkoKJvZc_KJ53d8QrNoMEQe-kH-4lo8/edit?usp=sharing
formula for result 1:
=filter(A2:A,A2:A<=105)
formula for result 2
=filter("x"&A2:A,A2:A<=105)
Question: Why does the 'x' continue down in rows where the condition is not satisfied?
Because empty cells treated as zero 0. You can add an addition condition to FILTER() function to filter values greater than zero 0.
=FILTER("x"&A2:A,A2:A<=105,A2:A>0)

Google Sheet: How to find Highest Value along with the date for given set of data(date-value pair) in Google Sheet Formula?

I have below data in date-value pair format in Google Sheet:
Date
Value
1/8/2021
1301.85
1/11/2021
1303.9
1/12/2021
1320.05
1/13/2021
1291.55
1/14/2021
1287.45
1/15/2021
1270
I'm looking for a google sheet formula that will return output: highest value along with its associated date.
That means I'm trying to get the output as below:
1/12/2021 1320.05
You can also use the SORTN function.
The difference being, by using an INDEX formula you need to re-format the column A result to a date while using SORTN you don't.
=SORTN(A2:B,1,0,2,0)
How the SORTN function in our formula works
1 is "the number of items to return" (since we need just the max we set it to 1)
0 "Shows at most the first n rows" (this is the so called ties_mode, in our case 0)
2 is "the index of the column containing the values to sort by" which here is the 2nd column
0 "indicates how to sort the sort_column. TRUE (or 1) sorts in ascending order. FALSE (or 0) sorts in descending order".
try this:
=INDEX(SORT(A2:B), 2, 0), 1)
Another approach:
=index(A2:B,match(max(B2:B),B2:B,0))
Like this answer, you don't need to reformat the date.

How to index a list with array formula? (Google Sheets)

I am trying to use index to return values from a list created by an array formula. The array formula is:
aRRAYFORMULA(match(filter(full_list,startDate=N4,locationID=L4,service=M4),ID_list,0))
This array formula is essentially cross-referencing the filtered full_list with the ID_list to return positions of the ID's that are both in the full_list and ID_list. I'm now trying to turn the positions from the code above into the ID's found in the ID_list.
I've tried:
aRRAYFORMULA(index(ID_list,ifna(match(filter(full_list,startDate=N3,locationID=L3,service=M3),ID_list,0),""),1))
and
arrayformula(index(ID_list,aRRAYFORMULA(match(filter(full_list,startDate=N4,locationID=L4,service=M4),ID_list,0))))
but they only return the ID_list value for the first entry in the list. So say that the first formula returns 2 row positions, 4 and 20; the result of the formulas I've tried results is a single cell with the value for row position 4. The row position 20 is ignored.
Is there anything that I am doing incorrectly here and how do I fix this? Or, is there an easier way to achieve what I want, such as without an array formula?
I would forget about using INDEX altogether and just focus on an ARRAYFORMULA + FILTER + MATCH strategy:
=FILTER(ID_list,ARRAYFORMULA(ISNUMBER(MATCH(ID_list,full_list,0)))=TRUE)
If none of your ID_list values exist in full_list the formula will throw an error. If you want it to just report a blank, then add an IFERROR to your formula:
=IFERROR(FILTER(ID_list,ARRAYFORMULA(ISNUMBER(MATCH(ID_list,full_list,0)))=TRUE),"")
Hope it works for you!

Import vlookup data from a seperate Google sheet

I have a g-sheet and need to link cells from a imported g-sheet while using the vlookup formula. However, I can’t get it to work...
This is my formula:
=vlookup($A781,IMPORTRANGE("(link: https://docs.google.com/spreadsheets/d/1migJfXvK29d2bUm0pgZQQco-dOlAoNzfVoCrjIJ--uY/edit#gid=1509040177) docs.google.com/spreadsheets/d…",'SDC & MVC'!$A$1:$G,4,false))
This is my error message:
Wrong number of arguments to VLOOKUP. Expected between 3 and 4
arguments, but got 2 arguments
Any suggestions? What am I doing wrong?
The vlookup function takes 3 or 4 arguments and you have only provided two. I think you might need a closing parentheses ) on the IMPORTRANGE earlier before SDC & MVC'!$A$1:$G.
Try:
=vlookup($A781,IMPORTRANGE("(link: https://docs.google.com/spreadsheets/d/1migJfXvK29d2bUm0pgZQQco-dOlAoNzfVoCrjIJ--uY/edit#gid=1509040177) docs.google.com/spreadsheets/d…"),'SDC & MVC'!$A$1:$G,4,false)
Argments are as follows:
Search_key - is the value to search for (lookup value or unique
identifier). For example, you can search for the word "apple", number
10, or the value in cell A2.
Range - two or more columns of data for the search. The Google Sheets
VLOOKUP function always searches in the first column of range.
Index - the column number in range from which a matching value (value in the same row as search_key) should be returned.
The first column in range has index 1. If index is less than 1, a Vlookup formula returns the #VALUE! error. If it's greater than the
number of columns in range, VLOOKUP returns the #REF! error.
Is_sorted - indicates whether your Vlookup formula should return the
nearest match (TRUE) or exact match (FALSE).
Source: https://www.ablebits.com/office-addins-blog/2017/07/05/vlookup-google-sheets-example/
correct syntax would be:
=VLOOKUP(A781,
IMPORTRANGE("1migJfXvK29d2bUm0pgZQQco-dOlAoNzfVoCrjIJ--uY", "SDC & MVC!A1:G"), 4, 0)
eg: find value of cell A781 in spreadsheet with ID 1migJfXvK29d2bUm0pgZQQco-dOlAoNzfVoCrjIJ--uY in sheet called SDC & MVC in column A ...and if match is found return adjacent value from column D (4th column)

Google spreadsheet Multiple result with VLOOK UP

The VLOOKUP formulas which works individually are
=if(VLOOKUP(E2,DB!$C:$E,1,0)>0,"COMPLETED",)
=if(VLOOKUP(E2,DB!$F:$H,1,0)>0,"IN PROGRESS",)
The issue is while displaying both results in a single cell, the formula which I came up for this was
C2=if(AND(VLOOKUP(E4,DB!$C:$E,1,0)>0),"COMPLETED",if(VLOOKUP(E4,DB!$F:$H,1,0)>0,"IN PROGRESS","UNDEFINED"))
I have tested the formula with normal conditions other than VLOOKUP and it works without any issues, not sure what's wrong with it.
Example : C10=if(AND(E10=1),"ONE",if(E10=2,"TWO","NO DATA"))
Any help appreciated.
May be its something simple but I am pulling my hair out for the last 3 hours.
Thanks :)
/-----------------------/
Updated 03.05.2016
Sorry for the comments that I have posted as I am new at using Stack overflow.
I have tried with only IF statements without any AND conditions, but the result is still same. The VLOOKUP is not returning the second value.
C15=IF(VLOOKUP(E15,DB!$F:$H,1,0)>0,"COMPLETED",if(VLOOKUP(E15,DB!$F:$H,1,0)>0,"IN PROGRESS","UNDEFINED"))
What I am expecting in cell C2 (sheet1) is check the values in cell
E2 against the columns C:H ( Sheet 2/ DB). If it belongs to
Column C:C in (sheet2/DB) then the value in C2 (sheet1) should display
as "Completed" else if the value is in column F:F ( sheet2/DB) then in C2
(sheet1) should display "In Progress".
Link to my spreadsheet link
There are a few problems with your formula.
VLOOKUP and similar functions search within a single row or column, and it seems like you're looking for your value in multiple rows and columns.
As #Meta mentioned, VLOOKUP returns N/A when the value is not found in the range, and you are expecting a zero or less value to be returned (when you check for >0 in the IF statement). Note that VLOOKUP returns the cell value itself and not an index of a match (like the MATCH function).
My suggestion is to replace your VLOOKUPs with COUNTIF.
=IF(COUNTIF(DB!$F:$H,E2)>0,"COMPLETED",IF(COUNTIF(DB!$C:$D,E2)>0,"IN PROGRESS","UNDEFINED"))
COUNTIF counts in multiple rows and columns, and will return a zero if no matches are found.

Resources