I'm using Query function in Google Sheets but even if my files are set to locale Italy when I want to filters records with value that have numbers with decimal (commas not dot) example 10,45 the query return me error.
Example:
QUERY(A1:B3;"Select count(A) where B>" & B6 & " label count(A) ''")
where A1:B3 is a simple example table like:
Stefano 50,00
Fabio 42,00
Andrea 50,00
And B6 is a cell where you put the value you want. Example if I type 48 the query return me 2.
But if you put value with decimals, example 48,3, an error is returned.
Seems that locale in the properties of sheet is not recognized by Query command.
try:
=QUERY(A1:B3;
"select count(A)
where B > "&SUBSTITUTE(B8; ","; ".")&"
label count(A) ''")
or shorter:
=QUERY(A1:B3;
"select count(A)
where B > "&TEXT(B8; "#,#")&"
label count(A) ''")
Related
Can someone help me to build formula to get running total with two conditions brands and date using arrayformula?
exp for G4 i want to get sum of QTY before 11th Nov 2022 (F4) for brand D, DG and DA (G2) and so on until column F is not null.
Thanks.
This formula uses QUERY to sum the QTY and group up the given data by brand and date, than uses BYROW with INDEX and FILTER to get the RUNNING TOTAL of the QUERY.
BRAND to lookup need to be entered in range 'G2' and separated with ','(without space - separator can be changed at the last line of code).
You can edit the range at the bottom line of the code to change the range of reference.
Formula in range 'F4':
=ArrayFormula(LAMBDA(DATARANGE,SELECTEDBRAND,SEPARATOR,
QUERY(SPLIT(
LAMBDA(QUERY,
LAMBDA(COL_DATE,COL_TOTAL,
BYROW(QUERY,LAMBDA(ROW,
LAMBDA(DATE,TOTAL,
JOIN(";",DATE,SUM(FILTER(COL_TOTAL,COL_DATE<=DATE)))
)(INDEX(ROW,,1),INDEX(ROW,,2))
))
)(INDEX(QUERY,,1),INDEX(QUERY,,2))
)(
QUERY(
QUERY({DATARANGE},"SELECT Col3,SUM(Col4) WHERE "
&IF(NOT(ISNUMBER(FIND(SEPARATOR,SELECTEDBRAND))),
"Col2='"&SELECTEDBRAND&"'",
JOIN(" OR ","Col2='"&SPLIT(SELECTEDBRAND,SEPARATOR)&"'")
)
&" GROUP BY Col2,Col3 LABEL Col3 '', SUM(Col4) ''",1),
"SELECT Col1,SUM(Col2) GROUP BY Col1 ORDER BY Col1 ASC LABEL SUM(Col2) ''",0)
),
";"),"ORDER BY Col1 DESC",0)
)($A:$D,$G$2,","))
I have a column in a Google Sheet, which in some cases, includes multiple values separated by commas — like this:
Value
A example
B example
C example
D example
A example, E example
A example, F example
G example, D example, C example
I would like to count all occurrences of the unique values in this column, so the count should look like:
Unique value
Occurrences
A example
3
B example
1
C example
2
D example
2
E example
1
F example
1
G example
1
Currently, however, when I use =UNIQUE(A2:A), the result gives this:
Unique value
Occurrences
A example
1
B example
1
C example
1
D example
1
A example, E example
1
A example, F example
1
G example, D example, C example
1
Is there a way I can count all of the instances of letters, whether they appear in individually in a cell or appear alongside other letters in a cell (comma-seperated)?
(This looks like a useful answer in Python, but I'm trying to do this in Google Sheets)
try:
Formula in C1:
=INDEX(QUERY(IFERROR(FLATTEN(SPLIT(A1:A,", ")),""),"Select Col1, count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"))
Or, as per the comments, split on the combination instead:
=INDEX(QUERY(IFERROR(FLATTEN(SPLIT(A1:A,", ",0)),""),"Select Col1, count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"))
2nd EDIT: To order descending by count use:
=INDEX(QUERY(IFERROR(FLATTEN(SPLIT(A1:A,", ",0)),""),"Select Col1, count(Col1) where Col1 is not null group by Col1 Order By count(Col1) desc label count(Col1) ''"))
Assuming data in A1:A7:
In C1:
=SORT(UNIQUE(FLATTEN(ARRAYFORMULA(SPLIT(A1:A7,", ")))))
In D1:
=ARRAYFORMULA(MMULT(0+ISNUMBER(SEARCH(", "&ColumnCSpilledRange&", ",", "&TRANSPOSE(A1:A7)&", ")),ROW(A1:A7)^0))
Replace ColumnCSpilledRange appropriately.
I'm pretty new with ArrayFormula, have been trying but sometime the formula works, sometimes does not. What I'm trying to do is the combination of ArrayFormula, Countif for searching partial text.
As shown in the worksheet below, there are 10 subjects (column A), each subject has at least one of 4 samples (A,B,C,D) summarized as a string (column B). What I'm trying to do is to find which subject has sample A or B or C or D.
I have tried single formula for each sample, eg cell D3
=IF(COUNTIF($B3,"*"&$D$2&"*")>0,$A3,"")
it returns the correct results. However, when I try arrayformula in cell I3,
=arrayformula(IF(COUNTIF($B3:B,"*"&$D$2&"*")>0,$A3:A,""))
The answers are weird. For example: Subjects (Gamma, Zeta, Eta, Theta) who don't have the sample "A" are shown to have sample "A". And this applies to sample B,C,D too
Not sure what went wrong in here. Here is the link to the worksheet
I wouldn't use Countifs or an array formula. Use filter instead. Put this formula in cell i3.
=Filter(if(REGEXMATCH(B3:B,$D$2),A3:A,""),B3:B<>"")
try:
=INDEX(QUERY(IFERROR(TRIM(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B3:B, ","))="",,
SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"))
or use in row 2 if you want to sort it as in your example:
=INDEX(IFNA(VLOOKUP(A2:A, QUERY(IFERROR(TRIM(SPLIT(FLATTEN(
IF(IFERROR(SPLIT(B3:B, ","))="",,SPLIT(B3:B, ",")&"×"&A3:A)), "×"))),
"select Col2,max(Col2) where Col2 is not null group by Col2
pivot Col1 label Col2'Subjects'"), {2,3,4,5}, 0)))
You can accomplish all four columns of results with a single formula.
Delete all formulas from I3:L3.
Place the following formula into I3:
=ArrayFormula(IF(REGEXMATCH(B3:B,I2:L2),A3:A,))
In plain speech, this read "If anything in B3:B matches a value found in I2:L2, return A3:A in the matching columns(s) at the matching row(s); if not, return null."
I got an issue with Queries in Google Sheets.
I have these 3 Columns:
I would like to COUNT how many Rows have "A" in the first column and the SUM of B and C is more than 2.
This is the Query I tried:
=QUERY(Sheet5!A1:C7,"select COUNT(A) where A='A' and B+C>1 LABEL COUNT(A) ''", 1)
(I used LABEL COUNT(A) '' just to remove the header, the result doesn't change without it)
What am i doing wrong?
By using this Query, I get 1 as result (and it should be 2)
Try
=QUERY(Sheet5!A1:C7,"select COUNT(A) where A='A' and B=1 and C=1 LABEL COUNT(A) ''", 1)
=QUERY(Sheet5!A1:C7,"select COUNT(A) where A='A' and B+C>1 LABEL COUNT(A) ''", 0)
=COUNTIF(FILTER(A:C,A:A="A",B:B+C:C>1),"<>")/3
You can also use COUNTIFS and specify the conditions and the ranges for which they are applied:
=COUNTIFS(A1:A7, "=A", B1:B7, ">0", C1:C7, ">0")
Result
Reference
COUNTIFS.
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))