Compare two tab's headers, copy column below maintaining blank columns - google-sheets

I have two tabs, one with all of my column headers (data tab), the other tab with less headers, but all from the data tab.
I want to search the headers of the "data" tab using the headers from the second tab starting at column I through BI. The second tab's headers will periodically change but always be present in the data tab. If the search criteria isn't present, I want to leave that column blank. If it is present, return the values below from the data tab.
I've tried a few formulas, but can't quite get what I'm looking for.
This formula worked to find the data:
'FILTERED'!I2
=FILTER(data!I2:AK,COUNTIFS($I$1:$1,data!I1:AK1))
This formula got the placement right, but produced the wrong information:
'Copy of FILTERED'!I3
=ArrayFormula(IF(ISBLANK(I2:2),,FILTER(data!I2:AK,COUNTIFS($I$1:$1,data!I1:AK1))))
Here's my sheet.

You've got a large range to process, so there may be a slight delay filling the grid by formula (2 or 3 seconds maybe). But I have added a sheet ("Erik Help") with the following formula in I2:
=ArrayFormula(IF(ROW(A2:A),IFERROR(VLOOKUP(ROW(data!A2:A),{ROW(data!A2:A),INDIRECT("data!I2:"&ROWS(data!A:A))},HLOOKUP(FILTER(I1:1,I1:1<>""),{data!I1:1;SEQUENCE(1,COLUMNS(data!I1:1),2)},2,FALSE),FALSE))))
Honestly, it's hard to explain how this works, but I'll try to cover the basics.
=ArrayFormula(...)
This just means the formula will be processing a range rather than one cell.
IF(ROW(A2:A), ... HLOOKUP(FILTER(I1:1,I1:1<>""),{data!I1:1;SEQUENCE(1,COLUMNS(data!I1:1),2)},2,FALSE) ...)
IF(ROW(A2:A) is important, because it signals to do something for every row, thereby creating a 2D grid instead of just processing the current row. The HLOOKUP will look up every header in I1:1 that isn't blank [FILTER(I1:1,I1:1<>"")], which as the sheet is now, will be all of them. They will be looked up in in a virtual array formed from a top row consisting of all headers in data!I1:1 over a bottom row made up of a SEQUENCE of numbers made of 1 row and the same number of columns as are in data!I1:1, starting at the number 2 and moving up. (It starts at 2, because part of the VLOOKUP virtual array which I haven't explained yet, will be forming a column 1.)
VLOOKUP(ROW(A2:A),{ROW(data!A2:A),INDIRECT("data!I2:"&ROWS(data!A:A))}, *the HLOOKUP RESULT NUMBER*,FALSE)
Now a VLOOKUP will kick in. It will look up every row in data!A2:A within a virtual array made of two columns; the first column will be those same row numbers, and the second will be everything from data!I2 over and down (the INDIRECT setup allows this to be a dynamic grid in case you add or delete columns later). As to which column from that should be returns, that will pull from the HLOOKUP results explained above (which, as you'll recall, will all match the headers).
Finally, IFERROR(...) will return null if any step in that process returns an error, which would be because something wasn't found.

see:
=ARRAYFORMULA(QUERY(VLOOKUP(ROW(A2:A), {ROW(A2:A),
A2:C},
MATCH(HLOOKUP(E1:G1,
{E1, F1, G1;
B1, A1, C1},
2, 0), A1:C1, 0)
+1,
0),
"select *"))
for missing headers:

Related

Compiling a list using INDEX but need to skip certain rows

I'm compiling a list based on the first answers recieved between row N and AF.
I'm using these two formulas:
=INDEX(N2:O2,MATCH(FALSE,ISBLANK(N2:O2),0))
and
=INDEX(R2:AF2,MATCH(FALSE,ISBLANK(R2:AF2),0))
Is there a way to combine them whilst not searching in rows P & Q?
These are generated from a Form response so can't just be switched around.
try:
=INDEX({N2:O2, R2:AF2}, MATCH(FALSE, ISBLANK({N2:O2, R2:AF2}), 0))
If Sheet1 is an intake sheet of form results, you should not add any data, formulas or even formatting to that sheet. It virtually always causes issues. A form intake sheet should be left exactly as it is. A new sheet can then be used to bring over the results of the form intake sheet as you want to see them.
However, since you didn't specify any of that, I will supply a formula written to work in the same sheet as your posted example and in-sheet examples.
Clear an entire column and place the following in the top cell of that column:
=ArrayFormula({"Attendee Name"; IF(E2:E="",,IFERROR(REGEXEXTRACT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(FILTER(IF(N2:AK="",,N2:AK&"~"),N1:AK1=N1)),,COLUMNS(N1:AK1)))),"\s*([^~]+)"),"(none listed)"))})
This one formula will produce a header (the text of which you can change within the formula itself as you lie) and all valid results for all rows.
The inner IF will append a tilde (~) to any non-null entries in the range N2:AK.
FILTER will keep only those columns in this range where the header is the same as the header in N1 (i.e., "Attendee Name").
TRANSPOSE(QUERY(TRANSPOSE( ),,COLUMNS( ))) is colloquially called a "Query smash." It will form one cell from all horizontal results per row.
TRIM will cut any preliminary spaces and form a true string.
REGEXEXTRACT will pull the from the first non-space character up to but not including the first tilde (from those appended in the first step)—in other words, the first full valid entry from any column.
IFERROR will return a message if there is an error, with the likely error being that there were no valid entries for "Attendee name" in any column.
The outer IF will leave the cell blank if the no training event exists in E2:E.
{ } forms a virtual array that places the header over all other results.
ArrayFormula( ) signifies that multiple results will be processed at once.
Because this is an array formula that is being "asked" to process every row, you cannot manually type into any cell of this results column. If you do, you will "break the array"; everything except what you just typed will disappear, leaving only an error in the formula cell. If you need to add or change a name, you need to do that in the raw results range (e.g., manually type a name or a new name in Col N), which will then turn up in the formula output range.

Transpose a table row by row

I need to transpose parts of a table row by row. The following example illustrates what the result needs to look like:
I tried different combinations of arrayformula(), flatten() and transpose(), succeeded with getting the last column right with =arrayformula(FLATTEN(B4:C)), but need now help with fixing this.
Link to table
Try this in row 2 of the example screenshot:
={flatten({A2:A,A2:A}),arrayformula(flatten({if(A2:A<>"",B$1,),if(A2:A<>"",C$1,)})),flatten({B2:C})}
Or if you want the column headings, put this in row 1:
={"A","B","C";flatten({A2:A,A2:A}),arrayformula(flatten({if(A2:A<>"",B$1,),if(A2:A<>"",C$1,)})),flatten({B2:C})}
The new column 'C' ends up being a mixed data type, so be careful if you run a future query on these results as it doesn't like mixed data.
For local implementation (as per your initial screengrab, EU locale file), try this in cell E4 - since the formula sits in row 4, the array range needs to go from 4 (A4:A):
={flatten({A4:A\A4:A})\arrayformula(flatten({if(A4:A<>"";B$3;)\if(A4:A<>"";C$3;)}))\flatten({B4:C})}
Alternatively, if you want column headings, try this in cell E3 - the array range is still A4:A because "A"\"B"\"C"; puts headings in row 3, ; is a return, then the rest of the formula targets data from row 4 down:
={"A"\"B"\"C";flatten({A4:A\A4:A})\arrayformula(flatten({if(A4:A<>"";B$3;)\if(A4:A<>"";C$3;)}))\flatten({B4:C})}
If you want to limit the array range to a specific row rather than working down the entire sheet (eg. row 20), then A4:A would need to be A4:A20.
This is a basic SPLIT(FLATTEN( problem.
Arrayformula() can always exist on the outside of a formula and will apply to the whole thing.
This is on a new tab in your sample called MK.Help:
=ARRAYFORMULA(QUERY(TO_TEXT(SPLIT(FLATTEN(Data!A2:A&"|"&Data!B1:C1&"|"&Data!B2:C);"|";0;0));"where Col1<>''"))

Google Sheets Fill Down with Formula

I have a very hard problem to solve, which must be completed with a formula (not a script).
Basically, the Raw input column needs to be dynamically filled down until it hits the next piece of text.
Here's an example file with includes the expected output.
https://docs.google.com/spreadsheets/d/1ibqCvY39NlhCRWsbBdxKITUUpVpp9wXdEz44T-pHDY0/
Is it even possible to achieve?
Thanks
This will work based on your ask, assuming that A2 is never blank, place this in the first row of data (not header):
=ArrayFormula(IF(A2:A<>"", A2:A, B1:B))
It checks to see if there is a value in column A, if there is, it fills that column, if not, it copies the cell above.
Delete everything in Column B (including the header) and place the following formula in B1:
=ArrayFormula({"Header";VLOOKUP(FILTER(ROW(A2:A),ROW(A2:A)<=MAX(FILTER(ROW(A2:A),A2:A<>""))),FILTER({ROW(A2:A),A2:A},A2:A<>""),2,TRUE)})
Here is a basic explanation of how this formula works:
A virtual array is created between the curly brackets { }; this virtual array contains a header and all results. You can change the header name to whatever you like.
VLOOKUP looks up every row number that is less than or equal to the highest row number that contains text in A2:A. Each of these qualifying rows is looked up in a second array that contains only the row numbers and Column-A data from non-blank rows, returning the data itself. Since rows are in perfect ascending order and the last parameter of VLOOKUP is set to TRUE, all blank rows in the first array will "fall backward" to find the most recent row that did have something in Column A.

Sheet Query formula giving the incorrect output

I have a sheet where the query formula used is very simple.
Here is the test sheet
It just have to display the conetents of the second sheet in the first. Unfortunately, at some point the cell values are merged into single cells.
The example below shows till Apple1 to Apple 10 the data is merged in row 1.
I need a reason for this error and please avoid answering like, delete the row 15 of fruits tab sheet to correct.
Any cause for this is really appreciated.
Sheet2
Sheet1
QUERY has several arguments. If you don't include them, they are assumed to be defaults (with the third argument being to try to make the first row into a header). Try this instead:
=query(Fruits!A3:F,"Select *",0)
or you can leave the middle argument blank in your case:
=query(Fruits!A3:F,,0)

Google Sheets: Lookup last matching values but with expanding rows

I'm using a dynamic, expanding sheet containing form responses. Search keys are in A2:A, responses are in the Responses sheet. So,
To get an expanding VLOOKUP, I do:
=ARRAYFORMULA(VLOOKUP(A2:A, Responses!A2:C, 3, 0))
To get the last matching value (for example, latest timestamp) of a repeating search key, I use a combination of FILTER, MAX, and INDEX like so:
=INDEX('Responses'!C2:C, MAX(FILTER(ROW('Follow-up Responses'!A2:A), 'Responses'!A2:A=A2)))
And this works by just dragging it down, but is there a way to make this expanding in an ARRAYFORMULA function? I tried modifiying it as ranges but all I get is one row. My form responses are added quickly so there may come a time where the formula has not been dragged down to the most current.
Thanks!
Sample formula with lookup of last value using row:
=VLOOKUP(D2 ; SORT(FILTER({$A:$B\ROW($A:$A)};$A:$A<>"");3;0) ; 2;)
D2 -- search value
A:B -- initial
row(A:A) -- any row for getting last values in the top.

Resources