0

In my company employees should get a day off if:
1. they work on a friday nightshift(NS)
2. they work on a thursday NS and a saturday NS
3. they work friday morning and saturday NS.

I need to count how many dayoffs every employee should get

MORNING                                  NIGHT                   WEEKDAY |DAY
PLACE1|PLACE2|PLACE3 PLACE4|PLACE5|PLACE6|
DAV FL RI RI 1 10
DAV RI FL DAV 2 11
FL RI DAV FL 3 12
DAV RI FL DAV 4 13
FL RI DAV RI FL 5 14
DAV 6 15
FL DAV 7 16
DAV FL RI RI 1 17
DAV RI FL DAV 2 18
FL RI DAV FL 3 19
DAV RI FL DAV 4 20
FL RI DAV RI 5 21
FL DAV 6 22
RI FL 7 23

In this example FL gets 2 days off
RI gets 1 day off
DAV gets 2 days off

Counting the nightshifts of friday could be achieved with COUNTIFS.

=COUNTIFS(D3:D34,"DAV",G3:G34,"6")+COUNTIFS(E3:E34,"DAV",G3:G34,"6")+COUNTIFS(F3:F34,"DAV",G3:G34,"6")

but things get complicated when I have to use the name condition on 6 different columns, each with a different weekday condition, i.e employee on T+SAT or F+SAT, Is there any way to achieve this using only built-in formula w/o scripts?

2 Answers 2

1

You can try the following formulas:

Friday nights simply:

=SUMPRODUCT((L2=$D$3:$F$16)*(6=$G$3:$G$16))

Thursday nights + Saturday nights more complicated:

=MIN(SUMPRODUCT((L2=$D$3:$F$16)*(5=$G$3:$G$16)),SUMPRODUCT((L2=$D$3:$F$16)*(7=$G$3:$G$16)))

The principle of calculation is that Thursday nights worked are counted separately and Saturday nights are counted separately then from the two numbers are selected smallest. This in turn means that a person can work one week on a Thursday and after two weeks on a Saturday and get a day off. See if it's right.

Friday mornings + Saturday nights by analogy:

=MIN(SUMPRODUCT((L2=$A$3:$C$16)*(6=$G$3:$G$16)),SUMPRODUCT((L2=$D$3:$F$16)*(7=$G$3:$G$16)))

enter image description here

2
  • works! but as you noticed the day off is for T+SAT nights or F+SAT in the same week only. any suggestion?
    – danielbw75
    Commented Jan 30, 2020 at 7:55
  • I manage to do it slicing the ranges of the SUMPRODUCT() to 5 columns, itering it trough the sheet and suming everything up. something like this - =SUM(MIN(SUMPRODUCT((U38=$C$4:$E$8)*("ה"=$A$4:$A$8)),SUMPRODUCT((U38=$C$4:$E$8)*("ש"=$A$4:$A$8))),MIN(SUMPRODUCT((U38=$C$8:$E$12)*("ה"=$A$8:$A$12)),SUMPRODUCT((U38=$C$8:$E$12)*("ש"=$A$8:$A$12))),MIN(SUMPRODUCT((U38=$C$12:$E$16)*("ה"=$A$12:$A$16)),SUMPRODUCT((U38=$C$12:$E$16)*("ש"=$A$12:$A$16))), (...)
    – danielbw75
    Commented Jan 30, 2020 at 9:26
0

I transferred your sample data to a worksheet so that your morning shift data are in columns A:C and the night shift in columns E:G. The critical weekday column is column H. I presumed that your data have 1 = Sunday.

I created two named ranges, "AM" and "PM", to cover the columns for morning and night shifts. It's important that the ranges start from row 1. Note: It's also of critical importance that my formula not be written in a row above row 3 in the worksheet.

I added columns to your layout on the right, one for each employee, and wrote the employees' name in row 2 of each column. In my worksheet these columns are at K:M, and the formula goes to K3. From there it is copied to all other cells in my three columns.

=IF($H3=6,IF(COUNTIF(INDEX(PM,ROW(),0),K$2),1,""),IF($H3=7,IF(COUNTIF(INDEX(PM,ROW(),0),K$2),IF(OR(COUNTIF(INDEX(AM,ROW()-1,0),K$2),COUNTIF(INDEX(PM,ROW()-2,0),K$2)),1,""),""),""))

The three columns I added show a 1 for each earned off-day.

The formula discards all days which aren't either Friday or Saturday. On Fridays it awards a "1" if the name appears in the PM shift. For Saturday PM work and off-day is awarded if there was also work on either Friday AM or Thursday PM in the same week. From this rule follows that you can't start your months on the first day if that is a Saturday. The preceding Thursday must be included in the month's data. If it's not no error will occur (unless the formula is in row 2) but the result will be wrong due to the referenced row containing no valid data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.