mardi 20 septembre 2016

Assign a shift based on time and day

I have been struggling a lot with my nested "if" formula. I am trying to assign a specific working shift letter to a new column based on the time and day of the record in my sheet.

I created 2 new fields to make the calculation easier.

  • Using my "date" column ("m/dd/yyyy"), I created a column called "WeekDay" that basically displays the day of every record with a number from 1 to 7 (1 = Monday 5=Friday, etc).
  • Using my "time" column ("hh:mm AM/PM"), I created a column called "Hour of Day" that displays a number from 0 to 24 based on the time of my record (i.e:5:40 AM = 5)

The working shifts letters I want to use are as followed:

  • A shift - Mon to Fri from 6 to 14 hrs.
  • B shift - Mon to Fri from 14 to 22 hrs.
  • C shift - Mon to Fri from 22 to 6 hrs.
  • WD (Weekend Day) Shift - Sat and Sun from 6 to 18 hrs.
  • WN (Weekend Night) Shift -Sat and Sun from 18 to 6 hrs.

Below is what I have done, the code works but only for Shifts A, B and C. I cannot make it work, so, it also includes WD and WN.

=IF(AND([@[Hour of Day]]>=6,[@[Hour of Day]]<14,OR([@WeekDay]=1,[@WeekDay]=2,[@WeekDay]=3,[@WeekDay]=4,[@WeekDay]=5)),"A",
IF(AND([@[Hour of Day]]<22,[@[Hour of Day]]>=14,OR([@WeekDay]=1,[@WeekDay]=2,[@WeekDay]=3,[@WeekDay]=4,[@WeekDay]=5)),"B",
IF(AND([@[Hour of Day]]>=22,[@[Hour of Day]]<6,OR([@WeekDay]=1,[@WeekDay]=2,[@WeekDay]=3,[@WeekDay]=4,[@WeekDay]=5)),"C",
IF(AND([@[Hour of Day]]>=6,[@[Hour of Day]]<18,OR([@WeekDay]=6,[@WeekDay]=7)),"WD",
IF(AND([@[Hour of Day]]>18,[@[Hour of Day]]>0,[@[Hour of Day]]<6,OR([@WeekDay]=6,[@WeekDay]=7)),"WN","C")))))

Thanks for the help!

Aucun commentaire:

Enregistrer un commentaire