How to "counta" if some cell greater than 1 in Google Docs? - google-sheets

I have this data in my Google Spreadsheet
Col1 Col2
1 X
1
2 A
2 B
I want to make a formula to count Not Empty cell from Col2 but with condition that Col1 is greater than 1
Anyone know how to do it?

countifs can count based on multiple criteria.
Using it we can count only when:
Col1 is ">1"
and
Col2 is not empty (using wildcard "*" matching)
=countifs(A1:A4, ">1", B1:B4, "*")

Related

Max Sum of row within date range - Google Sheets

I am using Google Sheets.
I have names in first column, dates in first row, and numbers for each name/date.
I want to return the name and sum of numbers for the person who's sum of numbers is the largest (within date range.)
A cell formula for this would be better than a script.
It sounds straight forward but am going in circles and would appreciate help. Thanks Newman
Thank you.
try:
=INDEX(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"))
and for just 1 record:
=INDEX(QUERY(QUERY(SPLIT(FLATTEN(A3:A&"♦"&FILTER(B3:F, B2:F2>="2021-10-07"*1, B2:F2<="2021-10-13"*1)), "♦"),
"select Col1,sum(Col2) where Col2 is not null group by Col1 order by sum(Col2) desc label sum(Col2)''"), "limit 1", 0)

How can I avoid having to put 0s into the NULL fields to get a correct query calculation in Google Sheets

I have a Google Sheets question, which I have not been able to figure out yet with Google-Fu and RTFM:
Take the following spreadsheet as an example:
https://docs.google.com/spreadsheets/d/1IvMVaUdUDfYOoKyG0Uwd2n0M1mLjOTE5yZQ9K2R3q2M/edit?usp=sharing
In case the sheet gets lost in time, I am going to post its contents here:
Sheet1:
foo
withdrawal
deposit
C
4
10
D
10
E
10
4
As you see here, the withdrawal field for the D value being foo is empty, i.e. null
Sheet2:
foo
balance
C
=INDEX(QUERY({Sheet1!$A$2:C}, "SELECT SUM(Col3) - SUM(Col2) WHERE Col1 = '"&A2&"'"), 2)
D
=INDEX(QUERY({Sheet1!$A$2:C}, "SELECT SUM(Col3) - SUM(Col2) WHERE Col1 = '"&A3&"'"), 2)
E
=INDEX(QUERY({Sheet1!$A$2:C}, "SELECT SUM(Col3) - SUM(Col2) WHERE Col1 = '"&A4&"'"), 2)
The result is
foo
balance
C
6
D
E
-6
As you see, the balance field for the category D is null, although it should be -10.
The fix for that is to put a 0 into the deposit field in Sheet1 explicitly.
In my example, I get that data using a csv-export, and fields are generally empty and not 0, and it is cumbersome to add the 0 there. Is there a way to have something like COALESCE in that sum there (like in SQL)?
Please let me know.
it seems like something quite a bit simpler would avoid the problem:
=SUMPRODUCT(Sheet1!C:C-Sheet1!B:B,Sheet1!A:A=A2)
for cell B2.
Why don't you just add this in cell A1 of Sheet2 instead of all the Query:
=arrayformula({Sheet1!A1,"balance";if(Sheet1!A2:A<>"",{Sheet1!A2:A,Sheet1!C2:C-Sheet1!B2:B},)})
Obviously ensure cells Sheet2!A2:A and Sheet2!B1:B are empty.
If you have duplicate values of foo, try:
=arrayformula(query({Sheet1!A1,"balance";if(Sheet1!A2:A<>"",{Sheet1!A2:A,Sheet1!C2:C-Sheet1!B2:B},)},"select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col2) 'balance'",1))
A better option for a single-cell formula, referencing multiple sheets would be:
=arrayformula(query(
{Sheet1!A:A,n(Sheet1!B:C);Sheet2!A2:A,n(Sheet2!B2:C);Sheet3!A2:A,n(Sheet3!B2:C)},
"select Col1,sum(Col3)-sum(Col2) where Col1 is not null group by Col1 label sum(Col3)-sum(Col2) 'balance' ",1))

I want to sum value of of third column based on other two columns value in google sheets and col1 and col2 contains multiple duplicate values

https://docs.google.com/spreadsheets/d/1_MeiySJHI8OD84BPDOj_z57My-TXbs2ey4AOkQP3zug/edit?usp=sharing
I am sharing the link of sheet on which I want solution on that sheet also I have tried to explain you the question.
I have three columns I want sum of third col3 value based on first two column value
if col1 = 2 and col2 = 40; Then I should get the sum of all value in col3 in which col1 = 2 and col2 = 40
if the col1 contains value of 2 and col2 contains 40 than sum of col3 value only those col3 value in which col1=2 and col2=40
so if any of the column value changes than sum of col3 also sum according to that.
use:
={"result"; INDEX(IF(COUNTIFS(A2:A&" "&B2:B, A2:A&" "&B2:B, ROW(A2:A), "<="&ROW(A2:A))=1,
IFNA(VLOOKUP(A2:A&" "&B2:B,
QUERY({A2:A&" "&B2:B, C2:C},
"select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col2)''"), 2, 0)), ))}
In cell K4 I entered
={"Result Col"; ArrayFormula(if(len(G5:G),if(match(G5:G&H5:H,G5:G&H5:H,0)+4=row(G5:G),sumif(G5:G&H5:H,G5:G&H5:H,I5:I),),))}
I used the same formula (with different range) in E1 (for what I assume to be your 'real' data).
See if that helps?
The simpliest solution is to use a pivot table, see inside your spreadsheet. If you want the total inside the original data, and take advantage of this simple solution, you can then recall the total by GETPIVOTDATA

Google Sheets - How to COUNTIF multiple values in each one cell of column

Each cell has multiple values that separated by comma and I want to count a value.
Let say I want to count Mapping Your Future. How to do that?
delete everything you got and use:
=INDEX(QUERY(TRIM(FLATTEN(SPLIT(TEXTJOIN(",", 1, questionnaire!G:G), ","))),
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"))

COUNTIF with more than one matching string in Google Spreadsheets

I'm wondering how I can use COUNTIF with more than one matching string in Google Spreadsheets.
The following is the important part, I would like to count in the spreadsheet those records that contain "BAIRRO NOVO" and "Externo". These strings appear in different columns, not in the same cell.
=COUNTIF(IMPORTRANGE("10OAEb2fBfvAqCdp1yyuTBQ4NErtxtOyJ29whFkvVqaw";"Data!B:P");"BAIRRO NOVO")
This could be done with countifs but only if the data was placed in the sheet: i.e., importrange(...) is done and then countifs refers to its columns like
=countifs(C:C, "BAIRRO NOVO", G:G, "Externo")
To get this count without putting all the data in the current spreadsheet, use query
=query(importrange(...), "select count(Col1) where Col2 = 'BAIRRO NOVO' and Col7 = 'Externo'", 1)
Here Col1, Col2, ... are columns of the imported range; in your case Col2 is C, for example, because the range begins with B. The last parameter "1" is the number of header rows the queried range has: typically 0 or 1.
To make sure the output is a single cell, without a header like "count(something)", add an empty label as follows.
=query(importrange(...), "select count(Col1) where Col2 = 'BAIRRO NOVO' and Col7 = 'Externo' label count(Col1) ''", 1)
To have the query output 0 instead of #N/A when nothing is found, wrap it in iferror(..., 0):
=iferror(query(importrange(...), "select count(Col1) where Col2 = 'BAIRRO NOVO' and Col7 = 'Externo' label count(Col1) ''", 1), 0)

Resources