I have Data in Google Sheets Where multiple Dates are mentioned in single column. I want to separate the Each date and same row should be repeated for each date.
I would appreciate your help.
Trying with this but its not working.
=ARRAYFORMULA({"DATE","EMPLOYEE NAME";QUERY(IFERROR(SPLIT(FLATTEN(IFERROR(Sheet1!A:D
&CHAR(9999)&SPLIT(Sheet1!H:H,","),)),CHAR(9999)),),
"SELECT Col2, Col1 WHERE Col2 IS NOT NULL ORDER BY Col2 ASC",0)})
Sheet Link
I tried with this but its not spliting the dates.
function result(range) {
delimiter = ","
targetColumn = 8
var output2 = [];
for(var i=0, iLen=range.length; i<iLen; i++) {
var s = range[i][targetColumn].split(delimiter);
for(var j=0, jLen=s.length; j<jLen; j++) {
var output1 = [];
for(var k=0, kLen=range[0].length; k<kLen; k++) {
if(k == targetColumn) {
output1.push(s[j]);
} else {
output1.push(range[i][k]);
}
}
output2.push(output1);
}
}
return output2;
}
try:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(
A2:A11&"×"&B2:B11&"×"&C2:C11&"×"&D2:D11&"×"&E2:E11&"×"&F2:F11&"×"&G2:G11&"×"&
TRIM(SPLIT(H2:H11, ","))&"×"&I2:I11&"×"&J2:J11&"×"&K2:K11), "×", 0, 0),
"where Col8 is not null"))
update:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(FLATTEN(FLATTEN(
A2:A11&"×"&B2:B11&"×"&C2:C11&"×"&D2:D11&"×"&E2:E11&"×"&F2:F11&"×"&G2:G11&"×"&
TRIM(SPLIT(H2:H11, ",")))&"×"&TRANSPOSE(QUERY(FLATTEN(TRIM(SPLIT(I2:I11, ","))),
"where Col1 is not null", )))&"×"&TRANSPOSE(QUERY(FLATTEN(TRIM(SPLIT(J2:J11, ","))),
"where Col1 is not null", ))), "×", 0, 0), "where Col8 is not null", ))
or:
=ARRAYFORMULA(UNIQUE(QUERY(SPLIT(FLATTEN(FLATTEN(FLATTEN(
A2:A11&"×"&B2:B11&"×"&C2:C11&"×"&D2:D11&"×"&E2:E11&"×"&F2:F11&"×"&G2:G11&"×"&
TRIM(SPLIT(H2:H11, ",")))&"×"&TRANSPOSE(QUERY(FLATTEN(TRIM(SPLIT(I2:I11, ","))),
"where Col1 is not null", )))&"×"&TRANSPOSE(QUERY(FLATTEN(TRIM(SPLIT(J2:J11, ","))),
"where Col1 is not null", ))), "×", 0, 0), "where Col8 is not null", )))
Related
I have a QUERY that looks up values from various separate sheets, this is its input:
=QUERY( {
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col2, Col4, Col5 where Col1 IS NOT NULL and Col4 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col6, Col8, Col9 where Col1 IS NOT NULL and Col8 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col10, Col12, Col13 where Col1 IS NOT NULL and Col12 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col14, Col16, Col17 where Col1 IS NOT NULL and Col16 IS NOT NULL", 0), { "","","","","" } );
IFNA( QUERY({'Week 1'!A2:Z133;'Week 2'!A2:Z133;'Week 3'!A2:Z133;'Week 4'!A2:Z133;'Week 5'!A2:Z133},"select Col26, Col1, Col18, Col20, Col21 where Col1 IS NOT NULL and Col20 IS NOT NULL", 0), { "","","","","" } )
}, "SELECT * WHERE Col1 IS NOT NULL ORDER BY Col1")
The {} gets repetitive and longwinded, and requires manually updating every time I add another week.
Recently I discovered I can generate a list of Week sheet names using this formula:
=ARRAYFORMULA(
"Week " &
{1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30}
& "!A2:Z133"
)
and then in another column list only those sheets that actually exist:
=IF(
ISERROR(CELL("address",INDIRECT($U2))),
"",
$U2
)
Now I have a column with values such as Week1!A2:Z133, Week2!A2:Z133, etc. How can I use this column to create the QUERY formula source automatically?
Using this formula gets me the first range referenced but none of the subsequent ones in the column:
={ARRAYFORMULA(INDIRECT(AA:AA) )}
Here within this sheet is a basic script for combining tabs that start with the word "Week".
function tabCombo(){
var ss = SpreadsheetApp.getActive();
//Filters sheets to just the ones that start with "Week"
var sheets = ss.getSheets().filter(function (e){return e.getName().slice(0,4)=='Week'});
//combines all tab values into one array and filters out the rows with a certain value in the first column
var combo = sheets.map(e=>e.getDataRange().getValues()).flat().filter(e=>e[0]!='Header1');
//writes that new value to a 'Master' tab.
ss.getRange('Master!A2').offset(0,0,combo.length,combo[0].length).setValues(combo);
}
Take note of the word "Week" which is how it decides which tabs to grab.
Take note of the number 4 (which is how many letters "Week" has)
Take note of the range "Master!A2" which is the top left corner of where the combined data should go.
Take note of the term "Header1" which is how the combined array filters out the header rows from all the tabs.
I have a series of QUERY formulae which are joined together using {} syntax in google spreadsheets.
For example:
={
IFNA( QUERY('Week 1'!A2:Z33,"select Z, B, D, E where A = 'Bench Press' and D IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY('Week 1'!A2:Z33,"select Z, F, H, I where A = 'Bench Press' and H IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY('Week 1'!A2:Z33,"select Z, J, L, M where A = 'Bench Press' and L IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY('Week 1'!A2:Z33,"select Z, N, P, Q where A = 'Bench Press' and P IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY('Week 1'!A2:Z33,"select Z, R, T, U where A = 'Bench Press' and T IS NOT NULL", 0), { "","","","" } )
}
If the query does not find a result for the specific columns it returns {"","","",""} so that the {} does not break with mismatched data. As additional weeks are added, I add more rows to pull in the extra data so that I have a single sheet containing all workout data for "Bench Press" that I can process.
The problem is, this results in blank rows. How do I eliminate the blank rows using formulae without changing the structure of the Week 1 sheet or using scripts?
e.g.
I figured it out, wrap the {} in a Query formula that tests column 1 if it's null:
=QUERY( {
IFNA( QUERY({'Week 1'!A2:Z33;'Week 2'!A2:Z33;'Week 3'!A2:Z33},"select Col26, Col2, Col4, Col5 where Col1 = 'Bench Press' and Col4 IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY({'Week 1'!A2:Z33;'Week 2'!A2:Z33;'Week 3'!A2:Z33},"select Col26, Col6, Col8, Col9 where Col1 = 'Bench Press' and Col8 IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY({'Week 1'!A2:Z33;'Week 2'!A2:Z33;'Week 3'!A2:Z33},"select Col26, Col10, Col12, Col13 where Col1 = 'Bench Press' and Col12 IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY({'Week 1'!A2:Z33;'Week 2'!A2:Z33;'Week 3'!A2:Z33},"select Col26, Col14, Col16, Col17 where Col1 = 'Bench Press' and Col16 IS NOT NULL", 0), { "","","","" } );
IFNA( QUERY({'Week 1'!A2:Z33;'Week 2'!A2:Z33;'Week 3'!A2:Z33},"select Col26, Col18, Col20, Col21 where Col1 = 'Bench Press' and Col20 IS NOT NULL", 0), { "","","","" } )
}, "SELECT * WHERE Col1 IS NOT NULL" )
I also simplified the original queries input to avoid more QUERY calls, and as a bonus, I can sort the entire output using the outer QUERY
I've tried to add JOIN to this formula in every place I can think of, but none seem to be correct.
=ARRAYFORMULA(IFERROR(VLOOKUP(D2:D&E2:E,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦♥"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))
The results are multiple columns/rows. I want to keep the rows, but JOIN the column values with a ",".
my sheet
like this perhaps:
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(SUBSTITUTE(IFERROR(VLOOKUP(D2:D&E2:E,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦♥"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)), " ", "♫")),,999^99))), " ", ", "), "♫", " "))
I'm trying to take this QUERY:
=IFERROR(TRANSPOSE(QUERY(Items!$A$2:$D,"SELECT D WHERE A = '"&A2&"' and B = '"&B2&"' and C = '"&C2&"' and C is not NULL and D is not NULL", 0)),)
And turn it into a formula that I can enter one time at the top of a sheet and have it apply to all cells in the column below.
I've tried manipulating various other formulas and answers I've found/received here on SO, but getting nothing but errors.
My sheet
=ARRAYFORMULA(IFERROR(VLOOKUP(Estimate!A2:A&Estimate!B2:B,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(Items!A2:A&Items!B2:B))*(LEN(Items!C2:C)),
Items!A2:A&Items!B2:B&"♦"&Items!C2:C, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(Items!A2:A&Items!B2:B))*(LEN(Items!C2:C)),
Items!A2:A&Items!B2:B&"♦"&Items!C2:C, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(Items!A2:A&Items!B2:B))*(LEN(Items!C2:C)),
Items!A2:A&Items!B2:B&"♦♥"&Items!C2:C, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))
Thank you for that enormous formula! And to think I was trying to accomplish this using a simple FILTER. Would this be the appropriate modification to include another column (column C) in the search criteria?
=ARRAYFORMULA(IFERROR(VLOOKUP('task-itemAssociationsDV'!A2:A&'task-itemAssociationsDV'!B2:B&'task-itemAssociationsDV'!C2:C,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(taskData!A2:A&taskData!B2:B&taskData!C2:C))*(LEN(taskData!D2:D)),
taskData!A2:A&taskData!B2:B&taskData!C2:C&"♦"&taskData!D2:D, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(taskData!A2:A&taskData!B2:B&taskData!C2:C))*(LEN(taskData!D2:D)),
taskData!A2:A&taskData!B2:B&taskData!C2:C&"♦"&taskData!D2:D, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(taskData!A2:A&taskData!B2:B&taskData!C2:C))*(LEN(taskData!D2:D)),
taskData!A2:A&taskData!B2:B&taskData!C2:C&"♦♥"&taskData!D2:D, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))
I'm trying to generate unique values in D1:F but my formula is not working. For example, row 1 has
A B C
milk milk 44
the output should be:
D E
milk 44
here is my formula and my sheet
=ARRAYFORMULA(unique(A1:C))
UNIQUE works only in one dimension (row or column)
=QUERY(UNIQUE({A:A;B:B;C:C}), "where Col1 is not null", 0)
=ARRAYFORMULA(SPLIT(REGEXREPLACE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE({QUERY(QUERY(
UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(A2:A), "♠"&A2:A&"♦"&B2:D, )),,999^99)),,999^99)), "♠")), "♦")),
"select Col1, count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),
"select Col1 offset 1",0),
IF(QUERY(QUERY(UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(A2:A), "♠"&A2:A&"♦"&B2:D, )),,999^99)),,999^99)), "♠")), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0), "offset 1",0)<>"",
QUERY(QUERY(UNIQUE(SPLIT(TRANSPOSE(SPLIT(TRIM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(LEN(A2:A), "♠"&A2:A&"♦♀"&B2:D&",", )),,999^99)),,999^99)), "♠")), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0), "limit 0",1),)})
,,999^99))), ", ♀", ", "), ",$", ), "♀"))