google sheet : insert blank column in query output - google-sheets

I tried to extract some column from master table/sheet. I can use query() or filter() or vlookup() but for this example, i use this very simple formula in cell A100 :
={ calc_01!C15:C ,calc_01!F15:F }
It works fine and it will just output 2 columns in A and B column (start from row 100).
The problem is : how if i want the output into 3 column (A,B,C) where the 2nd column or column B will be empty. So i tried something like this , trying to make the 2nd column blank :
={ calc_01!C15:C ,"",calc_01!F15:F }
If i put it on cell A100, i expect the output will occupy column A,B and C (where B is blank). But it doesn't work. So does anyone know if possible to do it ?
Why i want to do this? because i have condition where on the top i have some kind of table formatting where the B column is too narrow and i'm not allowed to adjust its width, so i have to use column c instead of B.
Thanks.

Try
=index({ 'calc_01'!C15:C ,if(row('calc_01'!C15:C),,),'calc_01'!F15:F })
and see if that works?

Related

Finding the first value in a row and getting the address using ArrayFormula

in this example table, I want to get the first "failed" or "passed" from result 1, 2, and 3 column. I already made a formula to get the first mentioned value using:
=IF(C2=C2,CELL("address",INDEX(D2:F2,MATCH(C2,D2:F2,0))),)
which works fine (the column result is from that formula)
But when I'm trying to use ArrayFormula on the formula, it only shows the first row value only. my ArrayFormula is like this:
=ArrayFormula(IF(C2:C4=C2:C4,CELL("address",INDEX(D2:F2,MATCH(C2:C4,D2:F2,0))),))
i think its because the INDEX and MATCH doesn't update as it goes down, any idea how to fix this?
Sheets link: https://docs.google.com/spreadsheets/d/1oFTZHGd9PKpfZ9QXWvTshorEOGFxmD1cpeeQ9bIOYh8/edit?usp=sharing
You could use a query to get the minimum column matching the value in column C for each row in D to F:
=ArrayFormula(lambda(a,address(index(a,,1),index(a,,2)))
(query(split(flatten(if(C2:C="",,if(D2:F=C2:C,row(C2:C)&"|"&column(D2:F),))),"|"),"select Col1,min(Col2) where Col2 is not null group by Col1 label min(Col2) ''")))
Or alternatively you can use a formula similar to your original one with Byrow:
=ArrayFormula(if(C2:C="",,byrow(C2:F,lambda(r,CELL("address",INDEX(r,1+MATCH(index(r,,1),index(r,,2):index(r,,columns(r),0))))))))

google sheet : generate increment number

I use this formula:
=filter(calc!B7:B,calc!P7:P="")
to display the data from Col B of 'calc' sheet where the Col P is null or "".
it works fine and it will output single column. If i want to add index number (like incremental ID number) , i normally just manually add any formula that can generate increment number and it works.
But the problem is if the number of the output of that filter() was changed , then i have to readjust the index by extending it or deleting to match the number of the output.
I'm thinking if it's possible to embed the index number (increment number) into the formula itself , for example maybe like this :
=filter({ [my_index_number] , calc!B7:B },calc!P7:P="")
so to generate 2 column, where the left is the custom index_number column. Is it possible ?
Give a try on below formula. Adjust sheet name for other sheet. I have tested the formula to same sheet.
=ArrayFormula(IFERROR(SPLIT(SEQUENCE(COUNTA(FILTER(B7:B,P7:P="")))&"#"&FILTER(B7:B,P7:P=""),"#"),""))

google sheet : query to return row number rather than the value itself

I have this formula :
=filter(A10:A, R10:R=S10:S)
It will extract all data from column A with condition where the value of column R and S are equal. It works fine but i want it to output the row number rather than the value in column A.
How can i do this ?
Thanks
Use this:
=FILTER(ROW(A10:A), R10:R=S10:S)

IF cell contains, THEN return certain value with more values and return possibilities

I have a sheet with the following columns:
Column 1: contains text of the form "TS001", "TS002", "DR001", "MS002" etc.
The 2 letter in the beginning are a code for the manufacturer name, so for example "MS=Microsoft".
For the second column, I would like to have a formula that goes through the first column and searches for those letters, in order to then return the complete name of the manufacturer.
For example, it should look something like this:
Column 1
Column 2
MS001
Microsoft
TS002
Tesco
DR001
DR. Pepper
TS003
Tesco
Is something like that possible?
Thank you very much!
When you say "MS=Microsoft" it implies somewhere you have a table with that reference. For the purposes of the following example I created a sheet named ReferenceTable where column A contains the two letter code, and column B contains the name of the company. So it looks like this:
A
B
MS
Microsoft
TS
Tesco
And now in the main sheet in column B you would write the following formula:
=ARRAYFORMULA(VLOOKUP(MID(A1:A,1,2),ReferenceTable!A1:B,2,FALSE))
This will give you the name of the company, looked up from the reference table.
The array formula is there so that you only have to put this formula in cell B1, and assumes you will use the ReferenceTable sheet as a list; that way as you add records to Column A Column B is populated by the arrayformula in B1.
I'd simply use a Reference Table and a VLOOKUP formula
If cell B7 contains "MS0001"
the following formula will attempt to match just the first two letters again a reference table located in cells O7:P9
=VLOOKUP(MID(B7,1,2),O7:P9,2,FALSE)
and will return "Microsoft" when it finds "MS"
In order to achieve what you want, somewhere you need to have a list of the two letter codes and the corresponding company name.
As with all vba, there’s any number of ways to do this, but I would probably put the two letter code and company data into an array, then iterate through col1 to create the desired output for col2.
E.g below assumes the two letter code and company names are in col3 and col4 respectively, but you can change it to wherever they’re located.
Sub CompName()
Dim Cmpname () as string
Dim col1 as range, rng as range
Cmpname = range(range(“C1”), range(“D1048576”).end(xlup))
Set col1 = range(range(“A1”), range(“A1048576”).end(xlup))
For each rng in col1
For i = lbound(Cmpname, 1) to ubound(Cmpname, 1)
If left(rng, 2) = Cmpname(i, lbound(Cmpname, 2)) then
rng.offset(0,1) = Cmpname(i, ubound(Cmpname, 2))
Exit For
End if
Next
Next
End Sub
I’ve admittedly just written this on my phone and have not tested it, but hopefully there’s minimal mistakes.
I just reread your question and realized that you may actually want a formula rather than vba code.
If this is correct, using an INDEX MATCH is probably your best bet.
In this example I’ll assume the same setup as described above - col3 has company codes and col4 has company name - and this formula can be inserted into cell B1:
=index(D:D,match(left(A1,2),C:C,0))
You can then just filldown for the rest of the entries in col2.
Again, done from memory without testing so hopefully got it right.

Concat multiple columns in separate cells in Google Sheets

I have a very simple table of three columns:
I need to concat two of them (B and C) in separate cells like this:
desired result
I tried this formula: ==TEXTJOIN("-";TRUE;B1:C5) which does its work, but not the desired result. Please see the screenshot. The "D" column is what I get, and the "E" column is what I need to have:
What I get:
How do I achieve concatenating data of my columns in separate cells? Thanks.
Try this
=ArrayFormula(IF(B:B <> "",B:B&"-"&C:C,""))
It will populate the row with the string concatenation operand & (same as CONCAT()) dynamically, and if the B cell is empty it will leave an empty cell.
If you by any means have a table header, you can always have the range go from B2:B, having the formula like this:
=ArrayFormula(IF(B2:B <> "",B2:B&"-"&C2:C,""))

Resources