Power Query - Creating a Custom Column to show Text based on Times

HCW1966

New Member
Joined
May 6, 2016
Messages
20
Hi There,

Please i want to create a custom column based on the "Stop Time" column below. This column has approx 1,000 rows of information.

What i want to show on the Custom Column is

"Early Shift" if the stop time is between 07:00:00 and 14:59:59
"Back Shift" if the stop time is between 15:00:00 and 22:29:59
"Night Shift" if the stop time is between 22:30:00 and 06:59:59

The above is my primary question, however i have a secondary question, is it possible to create another column showing the Day of the Week (Sun, Mon, Tue..........) that corresponds to the StopTime column date.

Kind Regards Harry

1602675713717.png
 
Hi Sandy666,
Its almost perfect, the only issue that i have is that the last Else If Condition, never gets picked up, i have changed the order, and each time its always the last Else If Condition that never picks up. Its as if the code only looks at the first two Else If Conditions? Other than that its perfect.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
try this
Power Query:
if [StopTime] >= #time(7, 0, 0) and [StopTime] < #time(15, 0, 0) then "Early Shift" else if [StopTime] >= #time(22, 30, 0) or [StopTime] < #time(7, 0, 0) then "Night Shift" else "Back Shift"
check if each shift time exist
eg.
13:13:23SundayEarly Shift
16:06:25SundayBack Shift
22:44:49SundayNight Shift
 
Upvote 0
Hi Sandy666,

Yes each shift time exists, when i put in the new code i receive this error
1602759051382.png

try this
Power Query:
if [StopTime] >= #time(7, 0, 0) and [StopTime] < #time(15, 0, 0) then "Early Shift" else if [StopTime] >= #time(22, 30, 0) or [StopTime] < #time(7, 0, 0) then "Night Shift" else "Back Shift"
check if each shift time exist
eg.
13:13:23SundayEarly Shift
16:06:25SundayBack Shift
22:44:49SundayNight Shift


Hi Sandy666,

I finally got it, i changed the first condition to or and it seems to work. I really appreciate your help, and you have shown me so much with this code, so thank you.

Conditions = Table.AddColumn(Time, "Shift",
each if [StopTime] >= #time(22, 30, 0) or [StopTime] <= #time(6, 59, 59) then "Night Shift"
else if [StopTime] >= #time(15, 0, 0) and [StopTime] <= #time(22, 29, 59) then "Back Shift"
else if [StopTime] >= #time(7, 0, 0) and [StopTime] <= #time(14, 59, 59) then "Early Shift" else "Help")
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top