Google Sheets Query not pulling in select data - google-sheets

I'm sure this is a simple issue that I'm just missing, but I have this Sheet
which has a query function on the "Helper" sheet that should pull in the corresponding row for the job selected on the "Job Entry" sheet. However, for the second test job ("TEST002"), it is only pulling in the first 14 task names, but all 21 hours. Before I added TEST003, it was only pulling in 8 task names and the 21 hour slots, but I added 14 tasks to TEST003, and now 14 names come in. This is very confusing to me as both TEST001 and TEST003 pull correctly. This is the query I'm using to pull in the appropriate row from the database tab:
=query(Database!1:1000,"select * where A = 'Job' and D = '"&'Job Entry'!K5&"'")
I shared this slimmed down sample sheet just to make it easy to see, because I'm not exactly sure how to word the issue. But just for extra clarity, each job row from the one tab ("Database") has a location, a client name, 4 numbers for job, engine, head, and trans, up to 21 task names and up to 21 corresponding task allocated hours. For the one job that has all 21 tasks, it pulls in everything except for task names 15-20. Notably, there are three jobs in the database at the moment, this one with 21 tasks, TEST003 with 14 tasks, and TEST001 with 8 tasks (not important). Basically, it only brings in as many task names as the job with the second most tasks has.
I hope this is all clear enough for someone to help.
Thanks!

Be carefull with query when you have strings and numbers in the same column ! You need to transform with to_text. Try this
=query(arrayformula(to_text(Database!1:1000)),"select * where Col1 = 'Job' and Col4 = '"&'Job Entry'!K5&"'")

Here are other possible solutions:
=query( Database!1:1000, "where A = 'Job' and D = '"&'Job Entry'!K5&"'")
=FILTER( Database!1:1000, Database!A1:A1000 = "Job", Database!D1:D1000 = 'Job Entry'!K5)

Related

Across multiple rows, for each weekday in-between two dates, calculate a value, then sum by week and group by team member's name

I'm working on a team workload tracker to prevent my coworker from being overloaded with work and help them prioritize.
For this task, I must use Google Sheets.
Explanation:
Peter, John and Harry are all team members. They handle user requests all day every day. When they receive a request, they must enter into a table that looks like the "sample data" tab:
the workload (in days) they think they'll need to address it;
the date they'll start working on it;
the date they must finish it by.
End goal:
This is my end goal. I would like to have one row per team member, and one column per week of the year that shows this team member's total weekly workload across all the requests he's handled that week.
Notes:
They can have concurrent requests.
Requests can span multiple workweeks.
They work Monday-Friday.
A request that takes, say, 2 days to complete does not have to be completed in the 2 days that follow its start date (because it might not be urgent). For instance, a 2-day request that a team member decides to do over a period of 10 working days will take them (2/10) = 0.2 workday per day every day for 10 days.
Each member can (but shouldn't) have a weekly workload equal or greater than 5.
What I've done:
I've messed around with Pivot Tables but couldn't get to my end goal.
I've done the day view. I think I shouldn't use a column per day and somehow need to do all the calculation in (array?) formulas to get to the desired end goal, but I can't figure it out.
Any help would be greatly appreciated!
use:
=ARRAYFORMULA(QUERY(IFERROR(SPLIT(FLATTEN(IF(SEQUENCE(1; MAX(E2:E10-D2:D10))<=E2:E10-D2:D10+1;
A2:A10&"×"&WEEKNUM(D2:D10+SEQUENCE(1; MAX(E2:E10-D2:D10); 0); 2)&"×"&
INDEX(SORT(QUERY(QUERY(SPLIT(FLATTEN(IF(SEQUENCE(1; MAX(E2:E10-D2:D10))<=E2:E10-D2:D10+1;
WEEKNUM(D2:D10+SEQUENCE(1; MAX(E2:E10-D2:D10); 0); 2)&"×"&C2:C10&TEXT(D2:D10+SEQUENCE(1;
MAX(E2:E10-D2:D10); 0); "×ddd×")&ROW(D2:D10); )); "×");
"where not Col3 matches '^$|sam.|dim.|53'"; );
"select Col2/count(Col1),Col4 group by Col2,Col4 label Col2/count(Col1)''"); 2; 1);; 1)&
TEXT(D2:D10+SEQUENCE(1; MAX(E2:E10-D2:D10); 0); "×ddd×"); )); "×"));
"select Col1,sum(Col3) where not Col1 matches '53|^$'
and not Col4 matches 'sam.|dim.' group by Col1 pivot Col2"))

Finding duplicates across range and summing it up

I have a list of agents who are working on OT, but the challenge is that they have 2 entries for OT per day, and when i need to work on this data with another sheet i have to sort out the data and remove duplicates manually in order not to cause issues with vlookup.
I need the end result to be like this:
if any agents works OT 2 times a day then sum it up and place in one raw with the date.
i have made helpers columns to show the duplicates but the i got stuck with the next steps
here is the sheet for the example:
https://docs.google.com/spreadsheets/d/1rdqylI9Rr4CxPIJcffEsqfoHx0loPVrqi2UJAQ30Sos/edit#gid=0
use:
=QUERY(A2:C, "select A,B,sum(C) where C is not null group by A,B label sum(C)''")
and vlookup from it...

Combining multiple data from ID

I have a question for my current Spreadsheet A.
Now I'm trying to make a new sheet for report generation where:
Report shows each ticket recorded on spreadsheet A.
Each ticket have 3 recorded process time. (Verification, Repair, QA)
The month for when the job ticket is first registered.
For illustration purpose, new sheet should look like this:
Ticket ID
Verification
Repair
QA
Month
T-001
X Hour
Y Hour
Z Hour
9
T-002
X Hour
Blank if no recorded time
Blank if no recorded time
9
...
...
...
...
...
Can Google Sheets do that? If can, how do I do it?
I have tried looking for some tutorial videos on Vlookup/Hlookup/Query/Search/Find, but I cant seem to get the results I needed.
EDITED: Changed question 3 from Name to Month
My solution is not the most elegant but it works:
https://docs.google.com/spreadsheets/d/1dEMYbI751pp55YF5M0V19U0QbytsabgwAO_97I1LXqw/copy
First get all ticket names using UNIQUE formula
=unique(C3:C)
When you got it, you have to find rows using 2 conditions:
Process & Ticket. In order to get it using VLOOKUP I make temporary array that contains Process and Ticket columns stitched together and duration column.
Then I use VLOOKUP using 2 stitched keys
=ifna(
arrayformula(
vlookup(G2&$F$3:$F,ArrayFormula({$B$3:$B&$C$3:$C,$D$3:$D}),2,false)))
Ifna prevents from error messages displayed when no value is found.
First arrayformula lets work this formula for an entire column.
Last task is to determine name of an employee. I use vlookup, but as name is futher left then Ticket, I have to make a temporary array {C3:C,A3:A} to search for name.
Warning: Vlookup is listing only first name found on the list.

Query with array in condition in Google Sheet

I have 2 tabs:
Overview with the list of tasks and columns per each day when they should be done. The task can be open or completed several times.
Wall of shame - it should consist of Open tasks which deadline is over. The deadline should be filled in from line 1 in the Overview tab. If the task is overdue several times it should be specified as a new line with the new deadline.
I need help with the formula for "Wall of shame" tab.
Please see my example - https://docs.google.com/spreadsheets/d/1gaH-XCf9JtM0C2pJU9EidOk1hsLhmZ5J_b-5_0JUgyc/edit#gid=113767391
Try this in cell A1, deleting everything else in the 'Wall of Shame' sheet:
=arrayformula(
query({"Department"\"Activity"\"Owner"\"Deadline"\"Date open"\"Overdue, days";
query({
flatten(split(rept("|"&Overview!A2:A;columns(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0)));"|"))\
flatten(split(rept("|"&Overview!B2:B;columns(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0)));"|"))\
flatten(split(rept("|"&Overview!C2:C;columns(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0)));"|"))\
flatten(split(rept("|"&Overview!E2:E;columns(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0)));"|"))\
flatten(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0))\
if(flatten(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0))<>"";today()-flatten(query(iferror(split(flatten(trim(query(transpose(if(Overview!F2:AA="Open";if(Overview!F1:AA1<=today();Overview!F$1:AA$1;);));"";9^9)));" "););"";0));)
};"where Col6 is not null ";0)};
"select Col1,Col2,Col3,Col4,Col5,Col6";1))
I've put the whole thing in a query so you can decide which columns you want to select, ie, you could adapt to select Col1,Col2,Col3,Col4,Col6

Google Sheet: formula to loop through a range

It's not hard to do this with custom function, but I'm wondering if there is a way to do it using a formula. Because datas won't automatically update when using custom function.
So I have a course list sheet, each with a price. And I'm using google form to let users choose what courses they will take. Users are allowed to take multiple courses, so how many they will take is unknown.
Now in the response sheet, I have datas like
Order ID
User ID
Courses
Total
1001
38
courseA, courseC
What formula to put here?
1002
44
courseB, courseC, courseD
What formula to put here?
1003
55
courseE
What formula to put here?
and the course sheet is like
course
Price
A
23
B
33
C
44
D
23
E
55
I want to output the total for each order and am looking at using FILTER to do this. Firstly I can get a range of unknown length for the chosen courses
=SPLIT(courses, ",") // having named the Courses column as "courses"
Now I need to filter this range against the course sheet? not quite sure how to do it or even if it is possible. Any hint is appreicated.
try:
=ARRAYFORMULA(IF(A2:A="",,MMULT(IFERROR(
VLOOKUP(SPLIT(C2:C, ", "), {F1&F2:F, G2:G}, 2, 0))*1,
ROW(INDIRECT("1:"&COLUMNS(SPLIT(C2:C, ", "))))^0)))
demo spreadsheet
As I need time to digest #player0's answer, I am doing this in a more intuitive way.
I create 2 sheets to store intermediate values.
The first one is named "chosen_courses"
Order ID
User ID
1001
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
1002
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
1003
=IFERROR(ARRAYFORMULA(TRIM(SPLIT(index(courses,Row(),1),","))),"")
In this sheet every row is a horizontal list of the chosen courses, and I created another sheet
total
course price
=IF(isblank(order_id),"",SUM(B2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
=IF(isblank(order_id),"",SUM(C2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
=IF(isblank(order_id),"",SUM(D2:2))
=IFERROR(VLOOKUP('chosen_courses'!B2,{course_Names,course_price},2,false),"")
course_Names,order_id and course_price are named ranges.
This works well, at least for now.
But there is a problem:
I have 20 courses, so in the 2nd sheed, there are 21 columns. And I copy the formulas to 1000 rows because that is the maximum rows you can get to using ctrl+shift+↓ and ctrl+D. Now sometimes when I open the sheet, there will be a progress bar calculating formulas in this sheet, which could take around 2 mins, even though I have only like 5 testing orders in the sheet. I am afraid this will get worse when I have more datas or when it is open by old computers.
Is it because I use some resource consuming functions? Can it be improved?

Resources