On my spreadsheet, I have an "Organisation List" tab, "Schedule" tab and an increasing number of tabs per organisation, such as "BlueEdge Gym".
I have a QUERY formula that lists all dates from the different organisation's tabs schedules into one list on the "Schedule" tab. This makes a master schedule for me to view all organisations in chronological order, and I can see the next job.
Unfortunately, I have to manually add each organisations tab to this query in order to include them in the results.
I would like this to be dynamic from the organisation list, so that any organisation I add to my organisation tab list, will automatically/ dynamically be included into the list of sheets that the query on my schedule tab lists.
I would also like to have the Organisation name listed next to the date to which it corresponds, on the master schedule.
Here's the sheet:
https://docs.google.com/spreadsheets/d/1W3LSAjrshz3Mil6dsYVzKmR4fuL0Nojptl778ppTaEY/edit?usp=sharing
in A2 try:
=QUERY(SHEETNAMES(), "where not Col1 matches 'Schedule|Staff List|Organisation List'", 0)
and in E2:
=SORT(QUERY({
IFERROR(INDIRECT(IF(A2="", 0, A2)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A3="", 0, A3)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A4="", 0, A4)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A5="", 0, A5)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A6="", 0, A5)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A7="", 0, A7)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A8="", 0, A8)&"!D:F"), {"","",""});
IFERROR(INDIRECT(IF(A9="", 0, A9)&"!D:F"), {"","",""})},
"where Col3=FALSE", 0), 1, 1)
or try this more automated solution...
add script:
function onEdit() {
var sheet = SpreadsheetApp.getActive().getSheetByName("Schedule");
var src = sheet.getRange("A2"); // The cell which holds the formula
var str = src.getValue();
var cell = sheet.getRange("E2"); // The cell where I want the results to be
cell.setFormula(str);
}
and use this formula in A2:
=INDEX("=SORT(QUERY({"&JOIN(";", "'"&QUERY(SHEETNAMES(),
"where not Col1 matches 'Schedule|Staff List|Organisation List'", 0)&"'!D:F")&
"}, ""where Col3 = FALSE"", 0), 1, 1)")
Related
I would like this multiple-criteria query not to show empty columns.
=QUERY({H3:M11}, "select * WHERE
"&TEXTJOIN(" and ", 1,
IF(C3<>"", "Col2 = "&C3&"", ),
IF(B3<>"", "Col3 = '"&B3&"'", )), 1)
Besides, I would also like to know if it's possible to filter it outside a query formula. Currently, I have this formula made by #player0 which is excluding columns with values greater than 0, but I didn't manage to make it work for text.
=FILTER(FILTER(H3:M11, LEN(TRIM(QUERY(IFERROR(1/(1/H4:M11)),,9^9)))>0), {9;
LEN(TRIM(FLATTEN(QUERY(TRANSPOSE(IFERROR(1/(1/H4:M11))),,9^9))))}>0)
Link to the question where this filter formula was found.
Here's the sheet.
Thanks a lot.
try:
=ARRAYFORMULA(QUERY({H3:K11,
FILTER(L3:M11, TRIM(QUERY(L4:M11,,9^9))<>"")},
"where "&TEXTJOIN(" and ", 1,
IF(C3<>"", "Col2 = "&C3&"", ),
IF(B3<>"", "Col3 = '"&B3&"'", )), 1))
How can I query importrange where Col values = any of the range specified in another sheet?
For example:
=QUERY(IMPORTRANGE("/18UF6ZR19iWulTMHT3lg6mv0NLrghItzW6bRT_p7bzsA/","Data!A2:E"),"select Col4,Col3,Col1,Col2 where Col4 = '"&Helper!A2:A&"'",0)
This workbook has 3 sheets in it:
Data! = Data source
Helper! = Range required for the query to search for
Testing! = Is where I would like the data to return (Testing!A2 has the formula I have tried but it is not working as expected)
https://docs.google.com/spreadsheets/d/18UF6ZR19iWulTMHT3lg6mv0NLrghItzW6bRT_p7bzsA/edit?usp=sharing
I would like it to return data for the range Helper!A2:A but it is currently only returning the data from Helper!A2 I'm not sure what is going wrong as no errors return.
=QUERY(IMPORTRANGE("/18UF6ZR19iWulTMHT3lg6mv0NLrghItzW6bRT_p7bzsA/","Data!A2:E"),"select Col4,Col3,Col1,Col2 where Col4 matches '"&TEXTJOIN("|",TRUE,Helper!A2:A)&"'",0)
use:
=QUERY(IMPORTRANGE("18UF6ZR19iWulTMHT3lg6mv0NLrghItzW6bRT_p7bzsA","Data!A2:E"),
"select Col4,Col3,Col1,Col2
where Col4 matches '"&TEXTJOIN("|", 1, Helper!A2:A)&"'", 0)
So I know that empty cells are the worst for generating pivot tables however I have a huge csv that is generated like this:
ID
QTY
ITEM
DATE
800170
1
Donut
5/21/2022
800170
1
Bun
800170
1
Cake
800169
1
Sandwich
5/20/2022
800169
1
Cake
800169
2
Donut
800168
1
Donut
5/21/2022
800168
1
Cookie
800168
1
Tea
800167
1
Donut
5/22/2022
800167
1
Tea
and this is the pivot table that gets generated from it.
I am wondering if there is a way to have the dates "merged" by ID as an ID will always have the same Date?
Desired Output:
Here is a link to my test google sheet: https://docs.google.com/spreadsheets/d/1Loe3dCe4jqj14ZD7alYkb0IhkysOpArk5ZORtIahjdk/edit?usp=sharing
Unfortunately, the Pivot table has no function that will merge the data based on the ID. What you can do is to populate the date column of your raw data.
Here I created a script that will populate the data based on the previous value.
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Menu')
.addItem('Fill Dates', 'fillDates').addToUi()
}
function fillDates(){
var sh = SpreadsheetApp.getActiveSpreadsheet();
var ss = sh.getSheetByName("Sheet1");//Change this to your sheet name
var dLastRow = ss.getRange("D"+(ss.getLastRow()+1)).getNextDataCell(SpreadsheetApp.Direction.UP).getRow();
var startRow = 2;
var dateCol = 4
var range = ss.getRange(startRow, dateCol, dLastRow, 1);
var data = range.getValues();
var temp = '';
data.forEach(date =>{
if(date[0] != ''){
temp = date[0];
}else{
date[0] = temp
}
})
range.setValues(data)
}
To go to Apps Script, select Extensions > Apps Script. Copy paste the code above, save the script and refresh your spreadsheet. The script will create a custom menu in your spreadsheet and you can click that to run the script.
Demo:
Output:
Let me know if you have any issues or questions.
References:
Extending Google Sheets
Apps Script Spreadsheet Service
try:
=ARRAYFORMULA(QUERY({A2:C, VLOOKUP(ROW(D2:D), IF(D2:D<>"", {ROW(D2:D), D2:D}), 2)},
"select Col1,sum(Col2) where Col2>0 group by Col1 pivot Col4"))
or if you want totals:
=ARRAYFORMULA({QUERY({A:C, VLOOKUP(ROW(D:D), IF(D:D<>"", {ROW(D:D), D:D}), 2)},
"select Col1,sum(Col2) where Col2>0 group by Col1 pivot Col4"),
QUERY({A:B}, "select sum(Col2) where Col2>0 group by Col1 label sum(Col2)'Grand Total'");
{"Grand Total", TRANSPOSE(MMULT(TRANSPOSE(QUERY(QUERY({A:C,
VLOOKUP(ROW(D:D), IF(D:D<>"", {ROW(D:D), D:D}), 2)},
"select sum(Col2) where Col2>0 group by Col1 pivot Col4"), "offset 1", )*1),
SEQUENCE(COUNTUNIQUE(A2:A), 1, 1, ))), SUM(B:B)}})
or if you really love pivot table design:
demo sheet
I have multiple spreadsheets from which I am importing multiple sheets and then stacking the data vertically. The obstacle I am trying to move past is that every spreadsheet is a different company's information and when I query that information from another sheet that I made I am unable to differentiate the various sources of data from one another. Certainly, I could simply add a column to all of the original spreadsheets with the name of the company and include that in my query formulas, but I would rather use something more dynamic. Alternatively, maybe there is a way to ask a cell where it's value came from.
An example would be:
A2 = "San Diego" B2 = "$2.24" C2 = "Company 1"
A3 = "San Francisco" B3 = "$1.89" C3 = "Company 2"
A4 = "Indianapolis" B4 = "$4.21" C4 = "Company 2"
try something like:
=QUERY(QUERY(IMPORTRANGE("ID", "Sheet1!A:B"), "select Col1,Col2,'Company 1'", 0), "offset 1", 0)
then you could do array like:
={QUERY(QUERY(IMPORTRANGE("ID", "Sheet1!A:B"), "select Col1,Col2,'Company 1'", 0), "offset 1", 0);
QUERY(QUERY(IMPORTRANGE("ID", "Sheet5!C:D"), "select Col1,Col2,'Company 3'", 0), "offset 1", 0)}
I have a google sheet with 3 tabs. I want to have tab3 pull all rows from tab1 (southware) into tab3 if there is a match to any value on tab2 (Top)column B
=query(southware!B3:AA,"SELECT * WHERE I = '"&Top!B3&"' and D='112'", 0)
I can get it to pull all the rows for only 1 cell on tab2- how do I make it evaluate all the values in column B on tab2
See if this helps
=query(southware!B3:AA,"SELECT * WHERE I matches '"&TEXTJOIN("|", 1, Top!B3:B)&"' and D='112'", 0)
QUERY is not able to work with arrays that's why you will need to use FILTER:
=FILTER(southware!B3:AA, I3:I = Top!B3:B,
D3:D = "112")
but this will may have few limitations, so in such case use this one:
=QUERY(ARRAYFORMULA(VLOOKUP(Top!B3:B,
{southware!I3:I, southware!B3:AA},
{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}, 0)),
"where Col3='112'", 0)