I have this formula for counting matches in Contents!$B$2 in J4.
=ARRAYFORMULA(IF(NOT(REGEXMATCH(J4,
"\w")),0,SUM(COUNTIF(REGEXREPLACE(SPLIT(J4,","),"
[\s]",""),REGEXREPLACE(SPLIT(Contents!$B$2,","),"[\s]","")))))
The formula is in K4 but ideally, I want it to work right down J returning values to the relevant adjacent K. I tried this but it didn't work. Just filled the cell the formula was in
=ARRAYFORMULA(IF(NOT(REGEXMATCH(J4:J,
"\w")),0,SUM(COUNTIF(REGEXREPLACE(SPLIT(J4:J,","),"
[\s]",""),REGEXREPLACE(SPLIT(Contents!$B$2,","),"[\s]","")))))
I know I can just fill down but the issue is users inserting rows.
Thanks in advance for any assistance
=ARRAYFORMULA(IF(LEN(A2:A), IFERROR(VLOOKUP(A2:A,
QUERY(TRIM(TRANSPOSE(SPLIT(Contents!B1, ","))),
"select Col1,count(Col1) group by Col1", 0), 2, 0), 0), ))
Related
Need to reverse and transpose a row in google sheet
like below
Tried below formula but didn't reversed the order. Help me out!
=FILTER(TRANSPOSE(A1:E1),TRANSPOSE(A1:E1)<>"")
try:
=QUERY(SORT(FLATTEN(A1:1), FLATTEN(COLUMN(A1:1)), 0),
"where Col1 is not null")
or:
=INDEX(FLATTEN(VLOOKUP(ROW(A1), {ROW(A1), A1:1},
TRANSPOSE(SORT(SEQUENCE(COUNTA(A1:1))+1, 1, 0)), 0)))
=SORT(TRANSPOSE(A1:E1),SEQUENCE(COLUMNS(A1:E1)),)
SEQUENCE to create a array of sequential numbers
SORT to sort them in reverse
If you need to check for blanks, use QUERY to filter:
=QUERY(SORT(TRANSPOSE(A1:E1),SEQUENCE(COLUMNS(A1:E1)),),"where Col1 is not null",0)
Try
=query(sort(transpose({ARRAYFORMULA(column(A1:E1));A1:E1}),1,false),"select Col2")
Looking for a more efficient way, possibly array formula for Min/Max down a column. Not sure if array formulas work with this function as I can't get it to.
=ArrayFormula(MAX(INDIRECT("Data!E"&(K42:K169)&":E"&(K43:K170-1))))
=ARRAYFORMULA(MAX(VLOOKUP(K42:K169, {ROW(Data!A:A), Data!E:E}, 2, 0)&VLOOKUP(K43:K170-1, {ROW(Data!A:A), Data!E:E}, 2, 0)))
Note that I am using ROW(Data!A:A) instead of simply ROW(A:A) because the range in current sheet doesn't fit that of sheet Data!.
Here is my current code copied down columns in my sheet.
=MAX(INDIRECT("Data!E"&(K42-1)&":E"&(K43-1)))
Just need a more efficient way. Am I correct that using INDIRECT results in slow calculation times.
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(
INDIRECT("Data!E"&K42&":E"&MAX(K42:K))&","&IF(MOD(ROW(
INDIRECT("Data!A1:A"&COUNTA(L42:L)*K41)), K41)=0, "♦", ),,999^99), "♦")), ","),
"where Col2 is not null", 0)),
"select "&TEXTJOIN(",", 1, IF(LEN(L42:L),
"max(Col"&ROW(A42:A)-ROW(A42)+1&")", ))&"")),
"select Col2"))
I have a SUMIFS formula that works fine, but I have to drag it down to populate every column, which is quite impractical for the amount of data I have in my spreadsheet, therefore I want to turn it into an ARRAYFORMULA. The formula is supposed to calculate how many of a product was purchased in a month. It currently looks like this:
=SUMIFS(All!$N$3:$N, All!$AG$3:$AG, ">=1/1/2018", All!$AG$3:$AG, "<=31/1/2018", All!$L$3:$L, $A2)
All!N contains the quantity of an item the customer purchased, All!AG contains the date, and All!L contains the product code which is checked against the product code in column A.
I tried simply doing
=ARRAYFORMULA(SUMIFS(All!$N$3:$N, All!$AG$3:$AG, ">=1/1/2018", All!$AG$3:$AG, "<=31/1/2018", All!$L$3:$L, $A$2:$A))
but that only works for cell A2 - it just prints the same result as the other formula and doesn't carry on down the column, which is what I want it to do. That solution worked with a SUMIF formula I have (it does the same thing but doesn't check the date) but it won't work with SUMIFS. I'm not sure why and I'm not the best at troubleshooting these spreadsheet formulas so I'm hoping someone can help.
Update: Here is a dummy sheet showing the issue: https://docs.google.com/spreadsheets/d/1pX-icbJxmy8A0jhKLnSRxhZTLRgYFG_iU2BOQrseCCg/edit?usp=sharing
paste in B2 cell:
=ARRAYFORMULA(IF(LEN($A$2:$A), IFERROR(VLOOKUP($A$2:$A,
QUERY({All!$B$3:$D},
"select Col1, sum(Col2)
where Col3 is not null
group by Col1
label sum(Col2)''", 0), 2, 0), 0), ))
paste in C2 cell and drag to the right:
=ARRAYFORMULA(IF(LEN($A$2:$A), IFERROR(VLOOKUP($A$2:$A,
QUERY({All!$B$3:$D},
"select Col1, sum(Col2)
where Col3 >= date '"&TEXT( C$1, "yyyy-mm-dd")&"'
and Col3 <= date '"&TEXT(EOMONTH(C$1, 0), "yyyy-mm-dd")&"'
group by Col1
label sum(Col2)''", 0), 2, 0), 0), ))
spreadsheet demo
I have tried to use a COUNTUNIQUE function within ArrayFormula in cell 'A2' to get a result in the range like a column B that I've set a function cell by cell. But it returns only a single value. This is my formula in cell 'A2':
=ArrayFormula(COUNTUNIQUE(D2:D7,E2:E7,F2:F7,G2:G7,H2:H7))
Any help will be greatly appreciated!
This problem has interested me for a while. Basically, the solution from #player0 seems obvious to me. But it is difficult to read.
Perhaps using combined arrays and implicit endings search is more appropriate:
=INDEX(
COUNTIF(
UNIQUE(FLATTEN(
{"" & ROW(C2:Z), ROW(C2:Z) & "-" & C2:Z}
)),
ROW(C2:Z7) & "-*"
) - 1
)
you can do it like this:
=ARRAYFORMULA(QUERY(UNIQUE(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(D2:K<>"", "♦"&ROW(A2:A)&"♥"&D2:K, )),,999^99)),,999^99), "♦")), "♥"))),
"select count(Col1) where Col1 is not null group by Col1 label count(Col1)''", 0))
or like this:
=ARRAYFORMULA({
COUNTUNIQUE(D2:H2);
COUNTUNIQUE(D3:H3);
COUNTUNIQUE(D4:H4);
COUNTUNIQUE(D5:H5);
COUNTUNIQUE(D6:H6);
COUNTUNIQUE(D7:H7)})
In a Google sheet with form responses, I made an additional column where I want to look up from each submission if the value left of my new column already occurs in a range on another sheet.
So this is going to be a Vlookup formula finally.
Unfortunately, I didn't make it to the Vlookup part yet because the ArrayFormula part is not working.
I started off by looking to the cell value at the left with this formula, which worked, but the ArrayFormula part of it DOESN'T work.
=ArrayFormula(indirect(ADDRESS(ROW(), COLUMN()-1)))
I know that some functions don't work very well with ArrayFormula,
But I don't see any reason here this should not work because it's only looking to its row and its column.
I hope the image shows the problem well enough
If you just want to repeat the values from the previous column (let's say column A, starting in row 2), you can try in column B (also in row 2)
=Arrayformula(if(len(A2:A), A2:A,))
Change range to suit. See if that helps?
UPDATE: To repeat the previous column (anywhere you input the formula) try (in row 2)
=offset(A1, 1, column()-2, rows(A1:A))
To 'limit' the output you can use any number instead of rows(A1:A) or replace it with COUNTA(A1:A)...
you can do something like this, which will search for specific header across entire sheet and then return values of that column:
=QUERY({INDIRECT("Sheet1!"&
ADDRESS(1, MATCH("job ID", Sheet1!1:1, 0), 4)&":"&
ADDRESS(1000000, MATCH("job ID", Sheet1!1:1, 0), 4))},
"select * where not Col1 matches 'job ID' and Col1 is not NULL", 0)
without sheet name:
=QUERY({INDIRECT(
ADDRESS(1, MATCH("job ID", 1:1, 0), 4)&":"&
ADDRESS(1000000, MATCH("job ID", 1:1, 0), 4))},
"select * where not Col1 matches 'job ID' and Col1 is not NULL", 0)