I have this:
Column A
Column B
A1
B1
A2
B2
A3
B3
How do I concatenate every columnA values with every columnB values with a formula (or script) to have this:
Result
A1B1
A1B2
A1B3
A2B1
A2B2
A2B3
A3B1
A3B2
A3B3
I did it manually with "&" but couldn't manage to find the formula
You may try:
=INDEX(FLATTEN(A1:A3&TRANSPOSE(B1:B3)))
Incase the new functions have rolled out for you, try:
=INDEX(TOCOL(TOCOL(A:A,1)&TOROW(B:B,1)))
Use filter() to get just the non-blank values, transpose() to build all combinations, and finally flatten() to get the results in one column, like this:
=arrayformula( flatten( filter(A2:A, len(A2:A)) & transpose(filter(B2:B, len(B2:B))) ) )
Related
I have the yellow table shown below, and I'm trying to get the blue table, which aggregates columns B:F by value, and then counts the number of 'x' symbols for each row value of column A.
Is there some basic SQL/array magic formula to get this, please? There must be.
Use this new functions formula
=BYROW(B2:4, LAMBDA(v, COUNTIF(v, "=x")))
Used:
BYROW, LAMBDA, COUNTIF
v is the array_or_range
Update
={ A2:A4, BYROW(B2:4, LAMBDA(vv, COUNTIF(vv, "=x")))}
For fun
Update 02
=ArrayFormula(TRANSPOSE(QUERY({
QUERY(TRANSPOSE(IF(A1:4<>"x",A1:4,1)),
" Select * Where Col1 is not null ", 1)},
" Select (Col1),sum(Col2),sum(Col3),sum(Col4) Group by Col1 ", 1)))
For this sample table:
A
B
C
D
E
1
Range!A1:C5
URL1
= Formula here
2
URL2
3
URL3
4
...
I have this working formula in C1:
={IMPORTRANGE(B1, A1); IMPORTRANGE(B2, A1); IMPORTRANGE(B3, A1)}
A1 contains the range to pull from the target Sheets.
Links to the target Sheets are found in column B.
(This is a simplified example. My actual Sheet has 21 entries in column B.)
Question:
If I will have to add/remove URLs in column B, I have to adjust the formula in C1 and add/remove IMPORTRANGEs.
I would like to have a formula that automatically adjusts to the entries in column B.
Solutions tried:
I tried this, but it did not work:
={JOIN("", ARRAYFORMULA(IF(LEN(B1:B), "IMPORTRANGE(""" & B1:B & """, """ & A1 & """); ", "")))}
The JOIN function returns a text that should be identical to what the array { ... } parses as a formula. But it doesn't. Wrapping it with INDIRECT also does not work.
Any suggestions on how I could make this work?
if by "working formula" you mean valid formula that returns data then only thing you can do is hardcode it like this:
=QUERY({
IFERROR(IMPORTRANGE(B1, A1), {"","",""});
IFERROR(IMPORTRANGE(B2, A1), {"","",""});
IFERROR(IMPORTRANGE(B3, A1), {"","",""})},
"where Col1 is not null", )
A1:C5 = 3 columns = {"","",""}
you can generate formula dynamically with arrayformula but the result will be always a text string and not active formula. tho if you wanna go this way you will need a script that will convert your text string into active formula. example:
https://stackoverflow.com/a/73119313/5632629
https://stackoverflow.com/a/61819704/5632629
Given two sheets that look like this:
Sheet1
a1 b1
a1 b1
Sheet2
a2 b2
a2 b2
a2 b2
How could I query for both sheets and combine all the rows together to get something line
Combined
a1 b1
a1 b1
a2 b2
a2 b2
a2 b2
I have tried the following but none of them worked
={QUERY({'Sheet1'!A1:B},"select *");QUERY({'Sheet2'!A1:B},"select *")}
=QUERY({'Sheet1'!A1:B;'Sheet2'!A1:B},"select *")
The problem with both is that I don't specify what row to end at for the two sheets. If I changed it to =QUERY({'Sheet1'!A1:B2;'Sheet2'!A1:B3},"select *"), then it would work. The problem with this is that in my actual spreadsheet, the number of rows in the sheets is changing as I am inputting more data and I would rather not have to update the query everytime.
You were close. Include the full possible ranges and add a bit to the "Select" clause:
=QUERY({Sheet1!A:B;Sheet2!A:B},"Select * Where Col1 Is Not Null")
This returns only the non-null (i.e., existing) data from each sheet.
I have two sheets. I'm using SUMPRODUCT to sum a column based on a matching string.
=SUMPRODUCT(--(skus_campaign!A:A=A2),skus_campaign!D:D)))
This works exactly as expected, if I drag the formula to the rows below.
If I attach ARRAYFORMULA and and IF test to see if there's a blank value, it won't work.
=ARRAYFORMULA(IF(ISBLANK(A2:A), " ", SUMPRODUCT(--(skus_campaign!A:A=A2),skus_campaign!D:D)))
Am I missing something here? Is there an easier way to accomplish this while still using ARRAYFORMULA to grow and shrink the column based on the values in column A?
EDIT: Here's the link to the example Google Sheet. Column "D" under the "Data" sheet is the issue.
Try in E1
={"COGS"; ArrayFormula(if(len(A2:A), vlookup(A2:A, query(skus!A:D, "Select A, sum(D) where A <>'' group by A"), 2, 0),))}
and see if that produces the desired result. If it does, clear all values and formulas in column D and enter the formula in D1.
=ARRAYFORMULA({
AVERAGE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Data!D$2:E856<>"", "♠"&Data!D$2:E856&"♦"&Data!F$2:G856, )),,999^99)),,999^99), "♠")), "♦"),
"select Col2
where lower(Col1) contains '"&LOWER(A2)&"'
offset "&COUNTIF(Data!D$2:E856, A2)-6))})
I have the above formula that I am using. What this does is the following:
The last 6 times A2 shows up in either Column D or E, it accumulates the corresponding value in column F or G. Those 6 values are then turned into an average, as well.
I am trying to add one condition to this. I want it to only take those last 6 instances where column H and I are also something specific.
So when A2 shows up in column D, I only want to use the row if Column I is the value "X". When A2 shows up in column E, I only want to use the row if Column H is "X".
I am unable to get this implemented into my function myself and desperate for some help. One problem is that the "X" search is in reversed column order (ie. when A2 is in D, trying to search I...and when A2 is in E, trying to search G...which isn't the order those appear in the alphabet). Also just not sure where in formula this conditional even needs to go.
Data! just references the sheet I have my dataset dumped into, obviously.