Concat multiple columns in separate cells in Google Sheets - 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,""))

Related

google sheet : insert blank column in query output

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?

Lookup multiple values from one cell

Trying to obtain desired output shown in E:G from a data show in A:C. I can write a formula
JOIN(", ", FILTER($B$2:$B,$C$2:$C=E2,$A$2:$A=F2))
If there would be a single value in F2 I could get comma-separated output items from column B. But I need to do that for more than one value in F2 cell and get the output shown in column G. How to write a formula that can generate column G as desired?
Any help is welcome.
If you're happy with formula dragging down each cell, as per your example in cell F2, then G2 could be:
=join(",",unique(filter({$A:$A&"("&$B:$B&")"},$C:$C=$E2)))
There are more complex formula to do the calcs with an arrayformula.
Within the filter, there are {} brackets that are used to build an array of data. The array consists of Col A then ( then Col B then ).
It then works the same way as per your example in cell F2. The filter finds each row of the array where Col C matches the value in Col E. Unique and join get the results the same way.
When you drag down the formula, textjoin might be more helpful in ignoring empty cells than join.
Use this in cell F2:
=textjoin(",",true,filter(A:A,C:C=E2))
this in cell G2:
=textjoin(",",true,unique(filter(if($A:$A<>"",{$A:$A&"("&$B:$B&")"},),$C:$C=$E2)))
Using arrays in Google Sheets
https://support.google.com/docs/answer/6208276/using-arrays-in-google-sheets?hl=en-GB

Is it possible to use two cells of criteria to return a value from a third column?

I have an Google sheets file with two sheets. I'm trying to reference one sheet's text based on two cells of criteria using a formula in the other sheet. I have one sheet that looks similar to this -
And another that looks like this -
I would like to put a formula on the second sheet that basically says - look on the first sheet for the values in columns A and B and return me the value in column C. The tricky part is - the values in the second sheet may be inverted or there may be an instance where only one value is present, like in row 1 in the first sheet. Also the formula should only fill in a value if both columns match. All text combinations in both sheets are unique.
Is it possible to do this with text? Thank you for your help!
Try the following
=ArrayFormula((IFERROR(VLOOKUP(R2:R&S2:S,{O2:O&P2:P,Q2:Q},2,0))&
IFERROR(IF((R2:R<>"")*(S2:S<>""),VLOOKUP(R2:R&S2:S,{P2:P&O2:O,Q2:Q},2,0),""))))
(Do adjust locale and ranges according to your needs)
Functions used:
ArrayFormula
IFERROR
IF
VLOOKUP
If you can use two keys concated in the lookup table as a virtual key (i.e. make a key like "CAT|DOG"), then you can use that to look in the secondary table.
If you can't guarantee the sort order of the two keys in the secondary table, you can use the following technique to "sort" the two keys so you can make a single lookup key that's always in one stable order.
Sample Table
A
B
C
D
E
SortedKey
Cat
Dog
TRUE
Cat
Dog
CatDog
Dog
Cat
FALSE
Cat
Dog
CatDog
Formulas
Sample formulas for row #1.
For column C, use formula: =A1<B1
For column D, use formula: =IF(C1=TRUE, A1, B1)
For column E, use formula: =IF(C1=TRUE, B1, A1)
For SortedKey, use formula: =concat(D1, E1)

Google Sheets: How do I create an array from a range, adding a column with a constant literal value in every row?

I want to make an array with several columns. The second and subsequent columns are specified as a range pulled from another sheet. The first column is a static constant, that is, every cell in the first column should have the very same literal string value, say 'foo'. I can't find the correct syntax. I'd have thought something like this would work:
={"foo", 'Other Sheet'!C2:F}
but I get "Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 1. Actual: 999." Clearly "foo" needs to be "expanded" to a column with lots of rows. How do I do it, and where are tricks like this documented?
Maybe the answer to this question would give a start: How do I create an array containing a single column, every cell containing "foo", with the number of columns specified by a different range?
Here is an editable sheet illustrating the problem and the desired solution:
https://docs.google.com/spreadsheets/d/17myzKVFN3SDQuubWNdP-dFAbdvdlRbZFkjRpLi2Fas8/edit?usp=sharing
The exact question is this: what formula can I put in cell B9 of Sheet1 to get the current appearance of Sheet1? Notice that I don't know in advance how many rows there are in 'Other Sheet'. It's OK to assume that all rows of Other Sheet have a nonblank value in column C.
You can loop with an arrayformula and assign them to the first column, ending the array with the same size:
={ARRAYFORMULA(if(len('Other Sheet'!C2:C),"foo",)),'Other Sheet'!C2:F}
Side note: that between the {}, if you put a comma ({expr1 , expr2}), the value will be side by side, and if you put a semicolon ({expr1 ; expr2}), the values will be one above the other.
You can use QUERY for that:
=QUERY('Other Sheet'!C2:F, "select 'foo',C,D,E,F where C is not null")
If you want to remove the 'foo' column header, you can use:
=QUERY('Other Sheet'!C2:F, "select 'foo',C,D,E,F where C is not null label 'foo' ''")

Google Sheets - Concatenate 2 rows across columns into 1 cell

I'd like to achieve what's in the Desired Output column in the image below. I need to take what's in row 1 (id1, id2, etc.), add ":" to that, then concatenate it with the values under each of the Field columns, add "|" to each ID-Value pair, and get that all together into one cell. I need the formula to also work for empty cells, as the number of fields to concatenate together is dynamic.
So far I've tried a big CONCATENATE formula in one cell, but I can only get it to work for as many non-blank cells as I include in the formula.
Thanks in advance!
google-sheets
Use JOIN:
=arrayformula(join("|",filter($B$1:$E$1& ":" & B2:E2,B2:E2<>"")))
excel-formula
Use TEXTJOIN
=TEXTJOIN("|",,IF(B2:E2<>"",$B$1:$E$1 & ":" & B2:E2,""))
This will be an array formula and must be confirmed with ctrl-Shift-Enter instead of Enter when exiting edit mode.

Resources