Select a Value from a Range Based on Criteria from Another Sheet - google-sheets

First, I know this is really stretching what Sheets is meant to do, but here we are.
Sheet 1 is a list of meetings and who is assigned to run them (the larger sheet is extrapolated to many meetings across multiples days with many names):
Day
Activity
Assigned
Covering
Monday
Meeting #1
Smith
?
Monday
Meeting #1
Hansen
?
Monday
Meeting #2
Jones
?
Sheet 2 is who is eligible to be cover the meeting if the assigned employee is out:
Eligible Employee
Coverage Count
Attendance
Exclusion Day
Kelley
0.1
Present
Monday
Johnson
0.2
Absent
Tuesday
Ramirez
0.3
Present
Wednesday
Callahan
0.4
Present
Thursday
Basically, my manager wants a button he can hit to say "Hansen isn't here, who is covering them?"
The following logic would apply to select the correct Eligible Employee:
Coverage Count is the lowest/smallest in the range
Attendance = Present
Day != Exclusion Day
For above, if Hansen needed coverage, the logic would pass Kelley because they can't cover Monday, pass Johnson because they are Absent, and return Ramirez because they have a lower Coverage Count than Callahan.
In addition to returning Ramirez, the macro would also "record" a coverage for Ramirez of +1, so their Coverage Count would now be 1.3. That way if the manager then tried to find coverage for Jones next, Ramirez would not be returned again until everyone other Eligible Employee has covered again.
I'm stumped.
At first I tried using FILTER...
=FILTER(Covering_Emp,Covering_Duty<>"Friday",Dovering_Absence="Present",SMALL(Covering_Count,1))
But
I don't think what I need and
Throwing "“FILTER has mismatched range sizes”

try:
=BYROW(A2:A, LAMBDA(x, INDEX(IFNA(SORTN(
FILTER({F2:F, G2:G}, I2:I=x, H2:H="Present"), 1, 1, 2, 1)),,1)))

I think because of the somewhat recursive nature of this question it's easier to try a simple pull-down formula for it in the first place. So any people who have already been used as cover are excluded from the next round of selection using a countif on column D to add one to their coverage count:
=index(sort(filter({F$2:F,G$2:G+countif(D$1:D1,F$2:F)},H$2:H="Present",I$2:I<>A2),2,1),1,1)
starting in D2 and pulled down.
You can see that Kelley and Johnson are excluded because they are either absent or not available on Monday.

Related

COUNTA(QUERY()) does not produce the desired result

The "mirror" sheet contains data.
Column B of the "bonus" sheet calculates the number of projects in a given month in which the specialist is involved.
=COUNTA(query(mirror!$A$2:$B, "select B where
A <= date'"&TEXT(EOMONTH($A6,0),"yyyy-mm-dd")&"'
and
A >= date'"&TEXT($A6,"yyyy-mm-dd")&"'
ORDER BY B"))
On the "mirror" there are no projects for Dec 2020 and Jan 2021.
The counts function substitutes 1 for the "bonus" in these months, although 0 is expected.
I've already broken my head, I don't know how to overcome it. I would be grateful for ideas.
Upd. Column A of the "bonus" sheet contains dates in the form of 8/1/2020, 9/1/2020, 10/1/2020, etc. beginning of the month.
In column A of the "mirror" sheet, the dates can be 10/5/2020, 10/31/2020, i.e. not necessarily the end of the month.
COUNTA counts an error as 1 (because it is "a non-null something"). So if your QUERY finds nothing, it will return an error — which will be counted as "one thing."
Try wrapping your QUERY in IFERROR, inside your COUNTA:
=COUNTA(IFERROR(QUERY(...)))
You can use SUMPRODUCT:
=SUMPRODUCT((MONTH(mirror!$A$2:$A)=MONTH(A2))*(YEAR(mirror!$A$2:$A)=YEAR(A2)))

How to sum specific information w/ multiple criteria including dates from form submission

I have a sheet that is linked to a google form so when a person submits the form, the information is populated into the sheet automatically with a timestamp, ex.1/17/2020 17:26:16. I'm trying to sum information based on multiple criteria and one is to only pull a full days worth of data but the formula is reading time as well and so I keep yielding 0.
For example, here is some data
1/8/2020 17:38:49 Danny PM Beetlejuice on Broadway 1144
1/8/2020 17:38:49 Danny PM Oklahoma! on Broadway 1181
1/8/2020 17:38:49 Danny PM Oklahoma! on Broadway 1000.5
1/8/2020 12:47:18 Jeff PM To Kill a Mockingbird 1675
1/8/2020 12:48:19 Jeff PM Jagged Little Pill 2390
On another tab I'm trying to calculate how much was spent by each person on this day. This new tab is looking at a persons shift and name to sumifs their spend:
=SUMIFS('Form Responses 1'!$E:$E,'Form Responses 1'!$D:$D,B$5,'Form Responses 1'!$B:$B,$A9,'Form Responses 1'!$C:$C,$B$2)
I don't believe you'll need to know what each piece in this current code means since I just need to add to it for it to read a range of dates and narrow down to one day.
I've tried adding the date range 'Form Responses 1'!$E:$E and having the criterion be the desired date filled in B2 but this is when it is reading for an exact match of the time from the range which is not going to work since I don't want it to read the time. I want to find a solution that won't involve having to manually update the submission data each time.
I've included a sample sheet here so whoever wants to try and tackle this can better see what it is I'm working with. In the review tab I have my current formula not specifying date and next to it the same but trying to specify the date.
Thank you in advance. My brain is a scattered mess so I hope everything makes sense.
If you want all records for the specified day to be included, you must use the >= and <= operators.
Something like this:
=SUMIFS('Form Responses 1'!$E:$E,
'Form Responses 1'!$B:$B, $A6,
'Form Responses 1'!$C:$C, $B$2,
'Form Responses 1'!$A:$A, ">="&$B$1,
'Form Responses 1'!$A:$A, "<="&$B$1+1)
In addition to the accepted correct answer, you could also try the following QUERY formula so you can get everything with just one formula instead of 5.
=IFERROR({QUERY(A:E,"select B, sum(E) where not A='' and C='"&H2&"' group by B label B 'Runner Name', sum(E) 'Total Spend' ",1),
QUERY(A:E,"select sum(E) where not A='' and C='"&H2&"' and todate(A)=date '"&text(H1,"yyyy-mm-dd")&"' group by B label sum(E) 'Totals per day' ",1)},
"No data")
(Please adjust ranges to your needs)
By using todate(A) we extract the date value from a timestamp.
The big advantage of using a single query is that -since you use the data from a form- your results will auto update as new answers come through.
Please feel free to ask if you need further information.
Another query that should work for you i've left on the new MK.Help tab in cell A5.
=ARRAYFORMULA(QUERY({INT('Form Responses 1'!A:A),'Form Responses 1'!B1:E},"select Col2,SUM(Col5) where Col1="&B1&" and Col3='"&B2&"' group by Col2 order by SUM(Col5) desc label SUM(Col5)'Total'"))
Agree with the previous poster that a query is the way to go since it'll autopopulate. Also it allows you to display the table in any order you like. I chose to sort by the total with the highest totals at the top.

How to group data by age range?

Given data list with two columns: 'Division' and 'Age.'
username year_of_birth
Albert Albo 1977
Bob Bilo 1974
Conan Cornic 1989
Don Duan 1954
Etan Etin 1967
Fabio Forio 1976
I want to put this data into a Pivot Table and group the ages into specified ranges; however, I'm having issues figuring out how to get around grouping them into set increments that don't vary. My first range would need to be 18-24, my next would be 25-29, then 30-34, 35-39, and so on until I hit 64. Then, I would have 65+ all grouped into one, like so:
How could I make it work ?
A simpler (also single formula) might be:
=ArrayFormula(vlookup(year(now())-B2:B+1,Larry,2))
where year of birth is in ColumnB. This though does require a named range (Larry) of:
This repeats the assumption that, wanting month, day, time, everyone is treated as having been born at the very start of the year_of_birth.
A contingency is included for under 18s where 0-17 in the array might be replaced by invalid or such like.
Just for fun, let's see if we can make it in a single formula
Creating a pivot from here is trivial.

Automatically transform a log of check-in/check-out events into a time-sheet

UPDATE: Some context: A log that is fed automatically by a IFTTT script contains all check-in and check-outs for employees that work in a factory. I need to build a report with the first check-in for each day, and the last check-out for each day (employees might check-out for lunch, but come back and only the first check-in and last check-out should count).
My current solution is to calculate a "is first checkin or last checkout?" Boolean, and then feed this log into a pivot table for reporting purposes filtering out the repeat entries
My spreadsheet will have data inserted in columns D & E by a third party application (IFTTT or google forms), and I would like to use an arrayformula to automatically calculate one column as data come ins from those applications.
(D)Date (E)Time Calc
January 6, Friday 15:06 TRUE
January 6, Friday 15:15 TRUE
January 9, Monday 8:36 TRUE
January 9, Monday 10:04 FALSE
January 9, Monday 10:37 FALSE
January 9, Monday 15:51 TRUE
The formular for Calc is
=or(MIN(filter(E:E,D:D=D2,B:B=B2))=E2,MAX(filter(E:E,D:D=D2,B:B=B2))=E2)
How can I transform this formula into an arrayformula? From my experimentations it seems that ArrayFormula doesn't mix well with Filter. Help is appreciated!
So, the goal is to determine, for each date, whether the value in column E is the highest or lowest for that date. I think this is too much logic to pack into a single formula, but can be expressed by two array formulas. The first one creates two helper columns:
=arrayformula(vlookup(filter(D:D, len(D:D)), query(D:E, "select D, min(E), max(E) group by D", 1), {2, 3}))
This is itself a combination of two formulas: the inner query gets the minimum and maximum of E for each date in D; then vlookup aligns these min-max values with the rows of the original table. The filtering by len(D:D) is for performance reasons, to avoid looking up a huge number of empty cells.
Suppose the first formula was in G1; then it formed the columns G and H, which leads to E1 being
=arrayformula(not((E:E > G:G) * (E:E < H:H)))
Note that and and or are not arrayformula-friendly, but can be replaced by * and + which result in booleans getting implicitly converted to 0-1. The not function is array-friendly, and is used here partly to get a boolean back from an integer.
Inspired by #zaq, I solved by re-engineering the spreadsheet and got the solution by using the following formula:
=query(query(Sheet1!B:E, "select D, min(E), max(E) group by D pivot C,B ", 1),"select Col1, Col3, Col10,Col4,Col11")
This formula transforms a log of employee check-in and check-outs into a summarized "hours worked" table that contains,for each day, and for every employee, the first check-in and the last check-out.

Sum / Counting items in a column that match 3 criteria

Thank you ahead of time for anyone who can help me with this, I think I am close, but it still isn't working.
I have a simple sheet activity reporting sheet that I am asking staff to complete over the upcoming year - It has 5 columns:
Column A: Date -In format (4/4/2013 13:30:00)
Column B: Title -In format (text string)
Column C: Attendance -In format (Numbers)V
Column D: Vol led - In format (text string)
Column E: Staff Led - In format (text string)
Using this data I am 90 % positive that I can aggregate on a different summary sheet that contains some static data like months (in the B column) to aggregate on. I am having trouble configuring the criteria in the filters though to cause the correct output to either sum or count .
Quantity of events ed by either staff or vol, if neither box is checked the event should not be counted) Right now I am trying this but it is not working
=SUM(FILTER('Hostel Activities'!A:A,MONTH('Hostel Activities'!A:A)=$B3, NOT(AND(ISBLANK('Hostel Activities'!D:D),ISBLANK('Hostel Activities'!E:E)))
Total number of attendance in a month for activities led by staff or volunteers Right now I am trying this but it is not working
=SUM(FILTER('Hostel Activities'!A:A,MONTH('Hostel Activities'!A:A)=$B3, NOT(AND(ISBLANK('Hostel Activities'!D:D),ISBLANK('Hostel Activities'!E:E)))
THIE WORKS! ## Heading ##Total number of volunteer led activities in a month for activities Right now I am using this and it IS working
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,not(isblank('Hostel Activities'!E:E))))
Thank you for any assistance and/or guidance
Danny
The first problem I see with your first two formulas is that you're calling SUM on your FILTER result. But the FILTER is returning the column A, which are dates. So, your basically summing dates, which will surely not yield the result you're looking for. Why are you not using COUNT, as you did on your last formula?
Second, the first two formulas you pasted are identical, how do you expect them to return different results?
It seems that for the first two want to sum an OR condition. You can do this two ways (that I can think of now). The simpler to understand is just to sum two COUNT(FILTER(... formulas, one for each criteria, e.g.
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,not(isblank('Hostel Activities'!D:D)))) + B6
Assuming that on B6 is the other COUNT formula (the 3rd one, that already works).
Another option would be to use an OR function as criteria for the FILTER. Like this:
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3, OR(NOT(ISBLANK('Hostel Activities'!E:E)), NOT(ISBLANK('Hostel Activities1!D:D))) ))
I believe I have figured out a method that works by making some adjustments in the formulas and the source data.
Basically
IN THE SOURCE REPORTING DATA:
I combined columns D and E into the same column and added data validation so the coordinator has to enter if the activity is led by staff,volunteer, or neither.
IN THE MONTHLY AGGREGATION REPORT:
To count the number of activities led by either staff or volunteers I used this :
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Staff"))+E3
*E3 is the count of volunteer led activities which is found using this formula:
=COUNT(FILTER('Hostel Activities'!A:A,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Volunteer"))
Adding up the number of participants in activities run by either staff or volunteers was a little more difficult, but I was able to do it by adding up 2 unique equations. I would prefer using an OR statement in the filter criteria, but I just couldn't get that to work. This is how I was able to make it happen:
=SUM(FILTER('Hostel Activities'!C:C,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Staff")) + SUM(FILTER('Hostel Activities'!C:C,month('Hostel Activities'!A:A)=B3,'Hostel Activities'!D:D="Volunteer"))
Thank you all for your assistance

Resources