I have Google sheet with sum-ifs functions, but I need to make it apply to the whole columns instead of just one cell and to apply automatically to new rows when there added
I know that arrays don't work with sumifs after doing research but I can't seem to figure out to apply an array function to this.
=ArrayFormula(SUMIFS(K:K,C:C,C2,L:L,false))
so I tried instead to make it a =sum(if(and function instead with an array, but couldn't get that to work either. not sure how to get it to apply to the same affect as the above formula
I need to apply the following sum-ifs all the conditions are met to each cell in the selected column
basically like this:
=QUERY({C2:C, K2:L},
"select Col1,sum(Col2)
where Col1 is not null
and Col3 = FALSE
group by Col1
label sum(Col2)''", 0)
if you want to pair it with list of names then use VLOOKUP:
=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C, QUERY({C2:C, K2:L},
"select Col1,sum(Col2)
where Col1 is not null
and Col3 = FALSE
group by Col1
label sum(Col2)''", 0), 2, 0)))
Related
I want to rebuild my table of Col1 (key), Col2, Col3, Col4, Col5 to table of Col1 (Key), and Col2 (which include all accordance values from Columns 2,3,4,5...), please check example:
https://docs.google.com/spreadsheets/d/1je3uc1DHitzzsFK6Xag_ld531p7ozeheO4PwpCfZjQA
If I use the following plain text as range in Query:
=QUERY({A2:A7\B2:B7;A2:A7\C2:C7;A2:A7\D2:D7;A2:A7\E2:E7},"Select * where Col2 >0")
it works well. But I can't make that range to be dynamic inside query, I tried to put range (based on formulas or even as a text) in some cell and then pull it as follows
=QUERY(A1,"Select * where Col >0")
or
=QUERY({indirect(A1)},"Select * where Col2 >0")
but it doesn't work.
You can use this formula where you will need to change only one range in case there will be more columns:
=SORT(SPLIT(QUERY(FLATTEN(IF(B3:E = "",, A3:A & "♥" & B3:E)), "WHERE Col1 IS NOT NULL"), "♥"))
Or you could place A3:A and B3:E ranges in some cells as parameters and use INDIRECT you you need that:
=SORT(SPLIT(QUERY(FLATTEN(IF(INDIRECT(N4) = "",, INDIRECT(N3) & "♥" & INDIRECT(N4))), "WHERE Col1 IS NOT NULL"), "♥"))
When a raw data set may expand, I always recommend that the raw data set remain by itself in a sheet. For now, let's assume that you have only your existing raw data set in the 'Sample' sheet.
In a new blank sheet, place this formula:
=ArrayFormula(QUERY(SPLIT(FLATTEN(FILTER(Sample!A3:A,Sample!A3:A<>"")&"|"&FILTER(FILTER(INDIRECT("Sample!B3:"&ROWS(Sample!A:A)),Sample!A3:A<>""),Sample!B2:2<>"")),"|"),"Select * WHERE Col2 Is Not Null",0))
This formula is similar to what #kishkin offered. However, the FILTER inclusions automatically expand to include all parts of the raw data where there is something in Column A and a header added in B3:B. That is, this formula requires zero maintenance if set up as I've described.
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)''"))
I'm looking for a formula, =query possibly, that will turn this:
Into this:
I used the following formula successfully to get the AFTER picture, but I can't get the counts. I tried using concatenate but there isn't a way to do that to each item in the array. Maybe there is a way to do this using a query?
=transpose(split(join(",",unique(C1:C98)),","))
And here's my flavour of it, which also needs to be dragged to the right, to fill the other columns:
=ARRAYFORMULA(QUERY(
{UNIQUE(A$2:A) & " - " & COUNTIF(A$2:A,UNIQUE(A$2:A))},
"where Col1<>' - 0'",0))
Yes, you can use query to get the unique values and counts then join the two columns
=ArrayFormula(index(query(A2:A,"select A,count(A) where A is not null group by A label count(A) ''"),0,1)&"-"&index(query(A2:A,"select A,count(A) where A is not null group by A label count(A) ''"),0,2))
Apologies, in order to drag it across you would have to put:
=ArrayFormula(index(query({A2:A},"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"),0,1)
&"-"&index(query({A2:A},"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"),0,2))
Try the following in cell A2 and drag to the right.
=ARRAY_CONSTRAIN(ArrayFormula(IFERROR(CONCAT(UNIQUE(A2:A99)&" - ",
ArrayFormula(COUNTIFS(A2:A99,UNIQUE(A2:A99)))))),COUNTUNIQUE(A2:A99),1)
Also using a query
=ArrayFormula(index(query({A2:A},"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"),0,1)&"-"&
index(query({A2:A},"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"),0,2))
The only difference is that using the first formula you maintain the names within the order they appear, while using the query they get sorted alphabetically.
Functions used:
ARRAY_CONSTRAIN
ArrayFormula
IFERROR
CONCAT
UNIQUE
COUNTIFS
COUNTUNIQUE
Trying to understand if it is possible to apply ARRAYFORMULA to situations when QUERY is used in Google Sheets.
For example, I used QUERY for querying and aggregating a set of items, like so:
=QUERY($H$2:$I$17,"select sum(I) where H='"&A2&"' label sum(I) ''",0)
But in order to make that work across the spreadsheet, I will have to drag this formula down. There is also the ARRAYFORMULA thing, which is supposed to help with getting rid of excessive dragging, however it does not seem to work with QUERY, or am I just missing something?
A picture for a quick look:
And a shared file for the longer thinking:
https://docs.google.com/spreadsheets/d/1xOdqeESrFbrBknNYahSeF0ripA5fr2vVFQ-r--lkdA0/edit?usp=sharing
use this formula:
=QUERY(H2:I17, "select H,sum(I) where H is not null group by H label sum(I)''", 0)
and then you can do simple VLOOKUP like:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY(H2:I17,
"select H,sum(I) where H is not null group by H label sum(I)''", 0), 2, 0)))
Here two method alternatively:
first ==>
=arrayformula(sumif(H2:H,"=" & unique(filter(H2:H,H2:H<>"")),I2:I))
second ==>
=arrayformula(
query(
filter({vlookup(H2:H,{A2:A,row(A2:A)},2,false),H2:I},H2:H<>"")
,"Select sum(Col3) group by Col1 label Sum(Col3) ''"
)
)
As a game designer, I am working on Google Sheets to make collections of animals with specific outfits. I need to make sure I use all combinations are evenly used.
I could just use for-loop, but scripting here would add unnecessary complexity for the whole process and it would be nice to just do it in the Sheets like where I make the data needed for our game. I tried different combinations of MATCH, INDEX and COUNTIFS-functions. Dabbled a bit with Pivot Tables and QUERY, but my brain is stuck and I could use some help.
My data looks something like this:
Collection1:[Animal1][Outfit1][Animal1][Outfit7][...]
Collection2:[Animal6][Outfit3][Animal2][Outfit18][...]
[...]
So rows for collections with animal FOLLOWING the outfit it has in the next cell.
I'd like to have a sheet with Rows of animals with Columns for Outfits and Counts for those Outfits for that Animal.
I can't brain this and any hints would help. Sheets can be so unintuitive for me.
cell J1:
=QUERY({B:C;D:E;F:G},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1) 'animal count'")
cell J6:
=QUERY({B:C;D:E;F:G},
"select Col2,count(Col2)
where Col1 is not null
group by Col2
label count(Col2) 'outfit count'")
cell J12:
=QUERY({B:C;D:E;F:G},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
pivot Col2")