I have a Sheet with Column A being City and Column B being District, like so:
City
Districts
Accord
103
Albany
109,110,108
Altamont
109
I would like to transform this into the "opposite":
District
Cities
103
Accord
108
Albany
109
Albany, Altamont
110
Albany
I'm pretty sure it's simple. Thanks !
use:
=ARRAYFORMULA(QUERY(SPLIT(REGEXREPLACE(TRIM(FLATTEN(
QUERY(QUERY(SPLIT(FLATTEN(SPLIT(B2:B, ",")&"¤×"&A2:A&","), "×"),
"select max(Col2) group by Col2 pivot Col1"),,9^9))),
",$", ), "¤ ", 0), "where Col2 is not null", 0))
Related
I want to calculate in a pivot table the average duration between two changes (dates) for each item.
Here is the sheet that contains datas:
Item
Changed on
item3
2023-01-25
item2
2022-10-12
item3
2022-08-15
item3
2022-03-06
item2
2021-12-18
item1
2021-06-28
I need a pivot table to calculate the average duration of each item, like this:
Item
Avg. time between two changes
item1
no data
item2
298
item3
162.5
try:
=INDEX(LAMBDA(a, b, QUERY(QUERY({a, IFNA(VLOOKUP(a&"×"&
COUNTIFS(a, a, ROW(a), "<="&ROW(a))-1, {a&"×"&
COUNTIFS(a, a, ROW(a), "<="&ROW(a)), b}, 2, )-b)},
"select Col1,avg(Col2) where Col2 is not null group by Col1"),
"offset 1", ))(A:A, B:B))
=INDEX(LAMBDA(a, b, {SORT(UNIQUE(FILTER(a, a<>""))),
IFNA(VLOOKUP(SORT(UNIQUE(FILTER(a, a<>""))),
QUERY(QUERY({a, IFNA(VLOOKUP(a&"×"&
COUNTIFS(a, a, ROW(a), "<="&ROW(a))-1, {a&"×"&
COUNTIFS(a, a, ROW(a), "<="&ROW(a)), b}, 2, )-b)},
"select Col1,avg(Col2) where Col2 is not null group by Col1"),
"offset 1", ), 2, ), "no data")})(A:A, B:B))
=INDEX(LAMBDA(a; b; {SORT(UNIQUE(FILTER(a; a<>"")))\
IFNA(VLOOKUP(SORT(UNIQUE(FILTER(a; a<>"")));
QUERY(QUERY({a\ IFNA(VLOOKUP(a&"×"&
COUNTIFS(a; a; ROW(a); "<="&ROW(a))-1; {a&"×"&
COUNTIFS(a; a; ROW(a); "<="&ROW(a))\ b}; 2; )-b)};
"select Col1,avg(Col2) where Col2 is not null group by Col1");
"offset 1"; ); 2; ); "no data")})(A:A; B:B))
I want to filter with the week number in Col3 but the below function is producing an empty array.
=QUERY(Form Responses!A:T,"Select Col9,Col8,Col2,Col3,Col4,Col7,Col19,Col20, Col5, Col6, Col18 Where Col1 = 'On-time' AND Col3 ='"&WEEKNUM(TODAY())&"'",1)
use:
=QUERY(Form Responses!A:T,
"select Col9,Col8,Col2,Col3,Col4,Col7,Col19,Col20,Col5,Col6,Col18
where Col1 = 'On-time'
and Col3 ="&WEEKNUM(TODAY()), 1)
I need the range values to go from A:A, B:B, ..., [Current Column]. it needs to be dynamic for multiple columns, i.e Column D be =MAX(A:A, B:B, C:C), while Column E will be =MAX(A:A, B:B, C:C, D:D).
=MAX(COUNTIF(A:A, “*Text*”), COUNTIF(B:B, “*[Text String]*”), ..., [until current COLUMN() - 1])
Or something like
=MAX(
Loop ( COLUMN() - 1 )
{
COUNTIF(
INDIRECT(
ADDRESS(3, [Loop Iteration]) & ":" & ADDRESS([Dynamic Number], [Loop Iteration])
)
, “*[Text String]*” )
}
)
dragging solution:
=MAX(INDIRECT(ADDRESS(3, 1)&":"&ADDRESS(ROWS(A3:A), COLUMN()-1)))
non-dragging automated solution:
=INDEX(QUERY(QUERY(SPLIT(FLATTEN(COLUMN(A:E)&"×"&IFNA(HLOOKUP(
IF(FLATTEN(COLUMN(A:E)-1)>=COLUMN(A:E),,COLUMN(A:E)-(FLATTEN(COLUMN(A:E))-1)),
QUERY(SPLIT(FLATTEN(IF(A3:E="",, COLUMN(A:E)&"×"&A3:E)), "×"),
"select max(Col2) pivot Col1")*1, 2, 0))), "×"),
"select max(Col2) pivot Col1"), "offset 1", 0))
Here is the spreadsheet for testing: Click here to copy OR Click to View
I have a query result from some other source of data.
From this table I further need to merge the B and C columns with new line (char(10)) and that must be expected to look like below
But I have tried with Arrayformula and I am not successful.
=ARRAYFORMULA(query(Sheet1!A2:Z7,"Select A,B,C,D,E,F,G,H") & char(10) & query(Sheet1!A2:Z7,"select B") )
Try with an { array expression } like this:
=arrayformula(
query(
{ Sheet1!A2:H7, Sheet1!B2:B7 & char(10) & Sheet1!C2:C7 },
"select Col1, Col9, Col4, Col5, Col6, Col7, Col8",
1
)
)
...or perhaps more simply, like this:
=arrayformula(
query(
{ Sheet1!A2:A, Sheet1!B2:B & char(10) & Sheet1!C2:C, Sheet1!D2:H },
"where Col1 is not null",
1
)
)
I would like to import a sheet by 2 different filter function. The first one need to include every row where the value of column 14 is equal to 1, the second one need to exclude rows where column H contains one of those strings "alc" "alcool" "vin". I've seen it in previous questions here google-sheet-query-matches-function-doesnt-exclude-strings. However when i try to add the first filter into my previous formula it doesn't work, here is my formula :
=FILTER(
QUERY(
IMPORTRANGE("URL"; "Sheet!A:BE");
"SELECT Col1, Col3, Col4, Col26, Col8, Col30, Col40, Col41, Col44, Col45, Col49 WHERE Col14 = "1""
);
NOT(REGEXMATCH(IMPORTRANGE("URL"; "Sheet!H:H"); "(?i)alc|vin|alcool"))
)
I try both using and not using "" as the values of my column are numbers but none of them work
use:
=FILTER(QUERY(IMPORTRANGE("1RV1-mxrd4wjVBw8hNu1yQAOZvlaO0jD5Ar5AArg-7QE";
"wc-product-export-27-11-2020-1606486738987!A:BE");
"select Col1,Col3,Col4,Col26,Col8,Col30,Col40,Col41,Col44,Col45,Col49
where Col14 = 1");
NOT(REGEXMATCH(QUERY(IMPORTRANGE("1RV1-mxrd4wjVBw8hNu1yQAOZvlaO0jD5Ar5AArg-7QE";
"wc-product-export-27-11-2020-1606486738987!A:BE");
"select Col8
where Col14 = 1"); "(?i)alcool|vin|alc")))
or shorter:
=INDEX(QUERY(IMPORTRANGE("1RV1-mxrd4wjVBw8hNu1yQAOZvlaO0jD5Ar5AArg-7QE";
"wc-product-export-27-11-2020-1606486738987!A:BE");
"select Col1,Col3,Col4,Col26,Col8,Col30,Col40,Col41,Col44,Col45,Col49
where Col14 = 1
and not lower(Col8) contains "&JOIN(" and not lower(Col8) contains "; "'"&SPLIT(
"alcool|vin|alc"; "|")&"'")))