Count the number of full weekends worked (Sat&Sun) in an excel shift-work roster for each staff member over the current calendar year - excel-formula

I have an Excel rostering spreadsheet for shift workers and need to count the number of full weekends rostered (Sat&Sun) on/off for each staff member over the current calendar year.
I have tried several formulae, tried named ranges, countif, countifs etc. but am having problems counting identical values in two consecutive columns (days) in the same row i.e. Saturday and Sunday. Single day counts (such as number of Sundays worked) is no problem but I'm stumped with how to calculate the number of weekends when both days are rest-days, for example
The following works well for the number of single Rest Days (RD) falling on a Sunday but I need to determine the number of weekends in which both days(sat & Sun) are Rest Days.
=SUM(COUNTIFS(ROSTER!$M$17:$PM$17,"Sun",ROSTER!M28:PM28,{"RD"}))
The above is a small sample taken from a worksheet that contains a complete year's roster. Each roster is a two week block,starting on Sunday, with a column titled "RDFN" between the Sat and Sun at the end and beginning of the next fortnight.

Edit 2
As confirmed you want to count the number of weekends where both Sat and Sun are RD (Rest Day) in a given time frame.
I have revised my SUMPRODUCT formula (which works as COUNTIF in this case) to find the result for Jane. Simply drag it down to apply to other employees:
=SUMPRODUCT(((B5:AH5&C5:AI5)="RDRD")*((B$2:AH$2&C$2:AI$2)="SatSun"))+SUMPRODUCT(((B5:AH5&E5:AK5)="RDRD")*((B$2:AH$2&E$2:AK$2)="SatSun"))
This formula is using two SUMPRODUCT formula and adding the results from the two. Both SUMPRODUCT formula followed the same logic.
It will work in the case you have two columns between each fortnight, and it is actually slightly shorter than my previous
solution.
Let's take Jane's data for example. Imagine you have inserted four helper rows.
The formulas in the first helper row are B$2&C$2, C$2&D$2, and so on so forth till AF2&AG2, which represents SunMon, MonTue, TueWed, etc.
The formulas in the second helper row are B5&C5, C5&D5, and so on so forth till AF5&AG5, which represents RD8 M, 8 M14 A, 14 A14 A, etc.
So the first SUMPRODUCT formula is counting the number of RDRD in the second helper row when the corresponding position in the first helper row is returning SatSun.
First Part =SUMPRODUCT(((B5:AH5&C5:AI5)="RDRD")*((B$2:AH$2&C$2:AI$2)="SatSun"))
However the above formula is not working in situation where the last Sat of the first fortnight and the first Sun of the following fortnight are both RD because there are two columns in between which will not return RDRD in the second helper row so the match will fail.
To overcome the problem, I have to use a second SUMPRODUCT formula with the help from another two imaginary helper rows.
The formulas in the third helper row are B$2&E$2, C$2&F$2, and so on so forth till AF$2&AI$2, which represents SunWed, MonThu, TueFri, etc.
The formulas in the forth helper row are B5&E5, C5&F5, and so on so forth till AF5&AI5, which represents RD14 A, 8 M9 M, 14 A6 M, etc.
The second SUMPRODUCT formula is also counting RDRD in the forth helper row when the corresponding position in the third helper row is returning SatSun.
Second Part =SUMPRODUCT(((B5:AH5&E5:AK5)="RDRD")*((B$2:AH$2&E$2:AK$2)="SatSun"))
Adding the results from both parts will give you the total number of weekends where both Sat and Sun are RD as shown below:

Related

Counting lowest values from multiple columns

I have a table and I need to count expiration for a year but I have two columns and I need to count the lowest value from them. What function would help with this. Here is a small Example
Name Expiration date Break date
Nr.1 31-Aug-2019 28-Feb-2023
Nr 2 18-Oct-2018
Nr 3 30-Sep-2018 21-Jun-2017
Nr. 4 1-Jan-2018
AS you can see there will be here:
2017 2018 2019 2020
1 2 1 0
You could use an extra "helper" column which takes the minimum between the expiration date and break date. (Accounting for the possibility of the Break date being empty)
Then your equation to find the totals for each year would just be a simple COUNTIF on that new column.
Slightly shorter version of a formula for the helper column:
=YEAR(IF(COUNT(B2:C2)=2,MIN(B2:C2),B2+C2))
with the difference that this will return a year (other than 1900) if there is a blank in the Expiration date column that is next to a populated cell in the Break date column.
For the actual counts I would choose a technique that has been deemed off topic for SO.
Solution with no helper column
Formula:
=SUMPRODUCT(--((($B:$B<$C:$C)+($C:$C=""))*($B:$B<>"")*(YEAR($B:$B)=E$1))+((($C:$C<$B:$B)+($B:$B=""))*($C:$C<>"")*(YEAR($C:$C)=E$1)))
Assumptions:
Data in columns A:C, with Expiration Date in B and Break Date in C
Year (2017,2018,2019,2010) in E1:H1
The formula can be dragged horizontally from E2 to H2.
Formula Logic (pseudo-code):
IF(OR(AND(OR(B<C,C=""),B<>"",YEAR(B)=X),AND(OR(C<B,B=""),C<>"",YEAR(C)=X))) THEN TRUE
Alternate Solution Using Table
Because the headers break the original formula, you'll need to make the column references more specific to where the data actually is. A table is the easiest way to do that.
=SUMPRODUCT(--(((Table1[Expiration Date]<Table1[Break Date])+(Table1[Break Date]=""))*(Table1[Expiration Date]<>"")*(YEAR(Table1[Expiration Date])=$E1))+(((Table1[Break Date]<Table1[Expiration Date])+(Table1[Expiration Date]=""))*(Table1[Break Date]<>"")*(YEAR(Table1[Break Date])=$E1)))
Tables don't play nice with formulas dragged horizontally, so I put the years in a column:
=SUM(IF(YEAR(IF($B$2:$B$5
Note: This is an array formula, you must paste it in the cell, then hit ctrl+shift+enter and then you can copy and paste it across your table.
The cell works if your data is in A1:C5 and you have the years you want to test across E1:H10. You could then paste the above formula in E2, and then paste accross your table.
The array formula does the following:
The first IF statement checks to see which value is lower, ColB or ColC.
The embedded IF statements then check to make sure the values are not 0. If they are 0 they return the other column, if they are not 0, they return its own non-0 value.
The YEAR function extracts the year from each date.
The last IF function preformed (but the first written in the function) tests the year against the cell above the sum. If the year matches, it returns 1, if false, 0
The SUM statement simply sums all the true values

sum assigned vlaues if sum for each value meets a specific criterion

in excel, I have two columns. one containing months of the year (in numbers) each month number occurring in different number of rows, and in the second column I have a duration of time for each row (in hours and minutes).
now I want to do the following job with an excel function in just one cell (the same job could be done using a table with 12 cells, each for one month but I want to pack it all in one cell):
1- for each month number, sum all cells in the second column (time) which have that month number in the adjacent cell (this could be done with a sumif )
2- if that sum is more than 4 hours then return one for that month else return zero (this step could be done with a formula like this: IF(R10>(--"4:00");1;"") )
3. in the end the numbers assigned to each month summed together.
thanks to everyone who helps
the picture below, shows the steps:
enter image description here
Try,
=SUM(--(SUMIFS(Table1[time],Table1[month],{1,2,3,4,5,6,7,8,9,10,11,12})>TIME(4,0,0)))

Counting unique values in a column that matches multiple criteria in a single column

I'm trying to count how many values in column A multiple multiple criteria that are mixed in column B. I was able to do this using a helper column (column C). To better get the idea, please see below:
Row Column A Column B Column C
Day Shift Helper
1 Monday Worked AM Worked PM
2 Tuesday Worked AM
3 Wednesday Worked AM Worked PM
4 Monday Worked PM
5 Wednesday Worked PM
Column A contains days from Monday to Wednesday, column B contains shifts while column C contains a formula to return "Worked PM" if that day also has a "Worked PM" somewhere below. Basically, Monday and Wednesday has these in rows 4 and 5.
Formula for cell C1 is =IF(B1="Worked PM","",IF(COUNTIFS($A$1:$A$5,$A1,$B$1:$B$5,"Worked PM")>0,"Worked PM",""))
The reason why I have this helper column is because I want to count the days that have both "Worked AM" and "Worked PM" on them. In our example, the count formula should return 2. I used the following formula, which is working perfectly: =COUNTIFS($B$1:$B$5,"Worked AM",$C$1:$C$5,"Worked PM")
However, I wish to completely eliminate the helper column (column C), which I have failed to do ever since. I tried making use of SUMPRODUCT, COUNT+MATCH and COUNTIFS. I've seen tutorials on how to do this from different Excel help sites, but I've seen nothing that matched my concern. They were "close" (not sure), but when I reconfigure them, I always fail.
I've turned to here as my last stop before giving up. I want to ask if what I'm actually doing is impossible. If it is possible, I would as well seek your guidance on how can I arrive on the solution. Thanks in advance! :)
This will replicate the results from your helper column method. Enter as an array formula (ctrl+shift+enter):
=SUM(--IF(B2:B6="Worked AM",IFERROR(MATCH(A2:A6,IF(B2:B6="Worked PM",A2:A6),0),0)>0))
But unless you have duplicate row entries, wouldn't the count simply equal the number of repeats you have in column A? You don't have to enter this as an array formula:
=SUM(--(FREQUENCY(MATCH(A2:A6,A2:A6),ROW(A2:A6)-ROW(A2)+1)>1))

Conditional Sum (based on current week)

I have an excel 2010 Workbook. Within this there are two columns.
The first column represents numerical week 1 (1-52 rows), the second contains a numeric value (never blank)
I would like a formula which basically sums all the rows (2nd column) up until the current week. So today it would sum the rows 1 through 11, next week it would sum 1 through 12
Tried a SUMIF but could not get it working (always zero)
Try this:
=SUMIF(A1:A52,"<="&WEEKNUM(TODAY(),2),B1:B52)
Where your week numbers run from A1:A52 and your values run from B1:B52.
You can also define which day the week begins on within the WEEKNUM() function by changing the second parameter. It is currently set to 2 which is based on the week beginning on Monday.

Excel - how to get if a date is a specific day of the week?

I have a spreadsheet that tracks average file processing times over the course of a month. One of the macros and stats that we like to pull, is performance on Mondays (as the files are a little built up over the weekend). The spreadsheet is organized into columns by weekdays of the month:
The dates are formatted MM/DD/YYYY, so I would think Excel has a date function that it can determine weekday based on that date value.
Currently, I just have to manually tell the Macro which columns are Mondays, like so:
=AVERAGE(B20,G20,L20,Q20)
So, instead of manually, how would I get the average over the range of say, B20 to V20, only if the day of the week is Monday (the date cells are in row 1, so B1 to V1)?
To determine the weekday of a date in EXCEL use the =WEEKDAY() formula, which evaluates as 1 (Sunday) to 7 (Saturday)
e.g. If A1 contains 12/31/2016 (or 31/12/2016 if you're from where I'm from), the formual =WEEKDAY(A1) would evaluate to 7 (indicating that the last day of 2016 was a Saturday)
To apply this formula to your problem: (assuming that the dates are in row 1 and the values are in row 2)
insert a new row to hold the WEEKDAY() value (say, row 2)
in cell A2 type in =WEEKDAY(A1)
copy this formula as far right as necessary (to include all your dates)
Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3)
Possibly, you can add a column called [Day Of The Week] and use the following formula to display the day.
TEXT(B4,"dddd")
Then add an 'If'statement to your result cell.
simply
=SUMPRODUCT((MOD(B1:V1,7)=2)*B20:V20)/SUMPRODUCT((MOD(B1:V1,7)=2)*1)
should give the average of all values from B20 to V20 if the corresponding cell in row 1 is a monday.
the first part sums the values of all mondays and the second part counts them (sum / count = average) ;)
If you have any questions, just ask.
If your date is in A1, you can use =Text(A1,"dddd") to determine the day of the week (it will return the name, "Monday", "Tuesday", etc.) so then you could do perhaps:
=If(text(A1,"dddd")="Monday",[do whatever],[do whatever]) (may need a helper row/column to hold the text of the weekday)
(Or use AverageIf() and use the Text() idea.)

Resources