Power Query IF Time is

Freeman2022

New Member
Joined
Nov 3, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hello,

Is there a formula to use in Power Query for (If time is between 7PM and 7AM then After hours, if not then Business hours?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"Time", type time}}),
    AddColumn = Table.AddColumn(ChangeType, "Category", each if [Time] > Time.From(19/24) or [Time] < Time.From(7/24) then "After Hours" else "Business Hours")
in
    AddColumn

Book2
ABCDE
1TimeTimeCategory
25:08:56 AM5:08:56 AMAfter Hours
39:09:36 AM9:09:36 AMBusiness Hours
49:48:43 AM9:48:43 AMBusiness Hours
51:06:21 PM1:06:21 PMBusiness Hours
62:39:04 PM2:39:04 PMBusiness Hours
76:21:10 PM6:21:10 PMBusiness Hours
811:03:08 AM11:03:08 AMBusiness Hours
98:42:05 AM8:42:05 AMBusiness Hours
107:06:03 PM7:06:03 PMAfter Hours
118:33:16 PM8:33:16 PMAfter Hours
129:11:41 PM9:11:41 PMAfter Hours
1311:14:45 AM11:14:45 AMBusiness Hours
148:21:48 PM8:21:48 PMAfter Hours
159:17:33 AM9:17:33 AMBusiness Hours
164:15:13 PM4:15:13 PMBusiness Hours
174:53:21 AM4:53:21 AMAfter Hours
1812:06:39 AM12:06:39 AMAfter Hours
194:32:37 PM4:32:37 PMBusiness Hours
2010:31:37 PM10:31:37 PMAfter Hours
21
Sheet3
 
Upvote 0
Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"Time", type time}}),
    AddColumn = Table.AddColumn(ChangeType, "Category", each if [Time] > Time.From(19/24) or [Time] < Time.From(7/24) then "After Hours" else "Business Hours")
in
    AddColumn

Book2
ABCDE
1TimeTimeCategory
25:08:56 AM5:08:56 AMAfter Hours
39:09:36 AM9:09:36 AMBusiness Hours
49:48:43 AM9:48:43 AMBusiness Hours
51:06:21 PM1:06:21 PMBusiness Hours
62:39:04 PM2:39:04 PMBusiness Hours
76:21:10 PM6:21:10 PMBusiness Hours
811:03:08 AM11:03:08 AMBusiness Hours
98:42:05 AM8:42:05 AMBusiness Hours
107:06:03 PM7:06:03 PMAfter Hours
118:33:16 PM8:33:16 PMAfter Hours
129:11:41 PM9:11:41 PMAfter Hours
1311:14:45 AM11:14:45 AMBusiness Hours
148:21:48 PM8:21:48 PMAfter Hours
159:17:33 AM9:17:33 AMBusiness Hours
164:15:13 PM4:15:13 PMBusiness Hours
174:53:21 AM4:53:21 AMAfter Hours
1812:06:39 AM12:06:39 AMAfter Hours
194:32:37 PM4:32:37 PMBusiness Hours
2010:31:37 PM10:31:37 PMAfter Hours
21
Sheet3
PERFECT!!!! It works...Thank YOU
 
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,653
Members
449,462
Latest member
Chislobog

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