Arrayformula not populating all other rows when using index+match - google-sheets

Sample data: https://docs.google.com/spreadsheets/d/10H7hToEek7XxXpPiAtlj6n58db_83Njdaxxspk4pIO8/edit?usp=sharing
Im trying to populate the 1st column of sheet 1 based on the data on sheet 2. VLOOKUP wouldnt work because im comparing the 2nd column of sheet 1 to the 2nd column of sheet 2 and vlookup will only allow it if im comparing to the 1st column of sheet 2. I tried index+match and it worked for 1 row but when I try to use arrayformula to populate all rows, it never runs for all the other rows.
Here is the index+match formula im using: INDEX(Sheet2!A2:A,MATCH(B2:B,Sheet2!B2:B,0))
Here is the formula I use with arrayformula:
=ARRAYFORMULA(INDEX(Sheet2!A2:A,MATCH(B2:B,Sheet2!B2:B,0)))
How do I make this run for all rows and if this won't work is there a better way to go about this?

per slippy101: =ArrayFormula(VLOOKUP(FILTER(B2:B,B2:B<>""),{Sheet2!B:B,Sheet2!A:A},2))
per Dazrin: =ARRAYFORMULA(IF(B2:B="",,VLOOKUP(B2:B, {Sheet2!B2:B,Sheet2!A2:A}, 2, FALSE)))
Both formula works, the problem arises because INDEX doesn't work with ARRAYFORMULA pointed out by Dazrin as well.

Related

Sum every n columns starting at the 1st column in the range

In Excel/Google Sheets I have found how to sum every N columns on websites such as https://exceljet.net/formula/fixed-value-every-n-columns, but the problem is, from what I can see is that it starts at N column each time. I need something that starts from column 1 and then counts every N columns. like the following:
I need to do this with a formula and not a script.
With Google-Sheets, try:
Formula in M2:
=SUM(QUERY(TRANSPOSE(A2:J2),"Skipping "&L2))
Or, a single dynamic array formula (without dragging):
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(10,1,1,0)))
Or, more dynamic:
=INDEX(MMULT(A2:J4*(MOD(COLUMN(A2:J4),L2:L4)=1),SEQUENCE(COLUMNS(A2:J4),1,1,0)))
Note: The latter would also work in Excel with slight modifications.
Google sheets formula:
=SUM(FILTER(A2:J2, MOD(A2:J2, L2)=1))
then drag to other cells
or use this array version:
Array version:
=INDEX(TRANSPOSE(MMULT(A2:J4,TRANSPOSE(COLUMN(A2:J4)^0 *
N(MOD(COLUMN(A2:J4), L2:L4)=1)))), ,1)
If you want the cells that were added to be automatically highlighted.
Conditional formatting used on A2:J:
=MOD(COLUMN(), $L2)=1
In M2:
=SUMPRODUCT(A2:J2,N(MOD(SEQUENCE(,COLUMNS(A2:J2),0),L2)=0))
and copied down.
Try this formula on column M:
=SUM((sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2))+A2)
Here's the result on Column M.
Just to break down the code sumif(ArrayFormula(mod((COLUMN(B2:J2)-COLUMN(B2)+1),L2)),0,B2:J2) does the actual calculation with the number of intervals set on Column L but take note that I started at the 2nd column so the range here does not include the first column. The result from this is at the Column O highlighted red as you can see in the screenshot.
At the Column M is the actual solution where I only added the first column by using SUM on top of the previous formula.
I hope my explanation is clear.
Just copy/drag the formula down to each row and it should work.
Reference: How to Sum Every Nth Row or Column in Google Sheets Using SUMIF

Arrayformula inside an array in google sheets

I have the following formula in google sheets which works perfectly in the row 3.
=ArrayFormula(if(len($A$3:$A),vlookup($A$3:$A,'All records in progress'!A2:BE,{57,6,7,8,9,10,11,13,14,31,32,33},FALSE),""))
However, I would like to have the formula in the row 2 with the header so I was trying to create something like this:
={"Header"; ArrayFormula(if(len($A$3:$A),vlookup($A$3:$A,'All records in progress'!A2:BE,{57,6,7,8,9,10,11,13,14,31,32,33},FALSE),""))}
So I could have the word Header in the first row and the formula from the next row onwards. However, my formula is not working. Do you know if how I could achieve this?
Looking forward to your reply.
Cheers,
your vlookup returns 12 columns so you need:
={{"Header","","","","","","","","","","",""};
ARRAYFORMULA(IF(LEN(A3:A),
IFNA(VLOOKUP(A3:A, 'All records in progress'!A2:BE,
{57,6,7,8,9,10,11,13,14,31,32,33}, 0)), ))}

Using ArrayFormula to countif multiple columns and output the sum on each row

I've created a dense formula using COUNTIF and VLOOKUP across multiple columns, and I've currently set it up so that I have to copy/paste every formula. But I'd really like to be able to use arrayformula to write the formula once for each of the columns below, and have it render across at least 1000 rows. Is there a trick to writing this?
Column 1
=COUNTIF(VLOOKUP(F3,WarLinesValuesTypes,2,FALSE),"*Defense*")
+COUNTIF(VLOOKUP(G3,WarLinesValuesTypes,2,FALSE),"*Defense*")
+COUNTIF(VLOOKUP(H3,WarLinesValuesTypes,2,FALSE),"*Defense*")
+COUNTIF(VLOOKUP(I3,WarLinesValuesTypes,2,FALSE),"*Defense*")
+COUNTIF(VLOOKUP(J3,WarLinesValuesTypes,2,FALSE),"*Defense*")
Column 2
=COUNTIF(VLOOKUP(F3,WarLinesValuesTypes,2,FALSE),"*Offense*")
+COUNTIF(VLOOKUP(G3,WarLinesValuesTypes,2,FALSE),"*Offense*")
+COUNTIF(VLOOKUP(H3,WarLinesValuesTypes,2,FALSE),"*Offense*")
+COUNTIF(VLOOKUP(I3,WarLinesValuesTypes,2,FALSE),"*Offense*")
+COUNTIF(VLOOKUP(J3,WarLinesValuesTypes,2,FALSE),"*Offense*")
I also saw the StackOverflow post here (iterate row by row COUNTIF using ArrayFormula on Google Sheets), and tried to emulate it, but I am not getting it right. My sheet (https://docs.google.com/spreadsheets/d/1JR_eYvmf6YgW0CfzHrSR6dxF8RmyWhSKhqSpRnnbipk/edit?usp=sharing) shows the complex formula working correctly for both columns, as well as my failed attempt for 1 of those columns as a trial using arrayformula, mmult, and sign.
try:
=ARRAYFORMULA(MMULT(IF(REGEXMATCH(IFNA(VLOOKUP(
INDIRECT("F2:J"&COUNTA(B2:B)+1), 'Flattened Standard War Lines'!A:B, 2, 0)),
".*Offense.*"), 1, 0), TRANSPOSE(COLUMN(F:J))^0))

Preserving formula of a column when adding new rows in Google Sheets

I have a sheet which looks like this:
The C column is simply the product of column A and B. This formula is replicated in the entirely of column C, from row 2 to 1000.
However, if I add a new row between two existing rows, the formula is no longer there for that specific row. Looking around for solutions, I came across ArrayFormula. I changed my formula to the following:
=ARRAYFORMULA(IF(OR(A2="",B2=""),"",PRODUCT(A2:A, B2:B)))
However, this messed up the result. How can I solve this problem?
ARRAYFORMULA does not understand OR so you need to convert it into 0/1 logic:
=ARRAYFORMULA(IF(((A2:A="")+(B2:B="")), , A2:A*B2:B))

CONCATENATE cells in the column with ARRAYFORMULA

CONCATENATE cells in the column which separated by empty cells using ARRAYFORMULA. I have an idea but am not sure it is right. First of all get row number of first and last names for each day. Combine them in formula and finally put that formula to ARRAYFORMULA.
D2= =ARRAYFORMULA(IF(B2:B<>"",ROW(B2:B)+1,""))
E2= =ARRAYFORMULA(IF(C2:C<>"",IF(C3:C="",ROW(B2:B),""),""))
So the question is how to get the row number of the last name for each day in the same row as a day and how to combine this number to a formula which can be compatible with ARRAYFORMULA.
Example:
To get to the result (with steps in between) try (in a empty column in row 2)
=ArrayFormula(If(right(B2:B, 3)="day", offset(B2:B, 1,1)&", "&offset(B2:B, 2,1),))
and see if that works ?

Resources