PowerQuery, does not add 1 to next day time

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have StartTime and EndTime columns. I want to subtract End-Start and put the result in a new columns. So I used PowerQuery and I inserted a new columns with the following formula

= Table.AddColumn(#"Changed Type", "Custom", each [#"End-Time"]-[#"Start-Time"])

but to my surprise, Power Query can not do (next day time) thing. If the start was 10:00PM and the End is the next day 2:00am, power Query wont give you 4 hrs. See below please. Can that be fixed in PowerQuery. I know how to do a formula in Excel but I want to do it in PowerQ. Thank you very much.


Book5 (1).xlsx
ABCDEF
1Full NameDeptStart-TimeEnd-Time
2Oliver OlivierAccounting7:33 PM8:30 AM
3Anthony EllwoodIT2:25 PM4:22 PM
4Doug AndersonHuman Resources5:34 AM12:34 PM
5Danielle McneillIT1:31 AM1:12 PM
6Elena CliftonHuman Resources3:21 AM10:53 PM
7Angelica JohnsonOperations2:41 PM10:04 AM
8Camellia MorrisMarketing2:20 PM11:57 AM
9Domenic PlantOperations8:55 AM12:02 AM
10Manuel JonesManagement9:13 PM7:09 PM
11Johnathan WoodOperations6:58 PM11:35 AM
12Sharon UpsdellIT11:05 AM2:49 PM
13Barry HillMarketing8:26 AM5:03 PM
14
15
16Full NameDeptStart-TimeEnd-TimeCustom
17Oliver OlivierAccounting7:33:00 PM8:30:00 AM-0.460416667
18Anthony EllwoodIT2:25:00 PM4:22:00 PM0.08125
19Doug AndersonHuman Resources5:34:00 AM12:34:00 PM0.291666667
20Danielle McneillIT1:31:00 AM1:12:00 PM0.486805556
21Elena CliftonHuman Resources3:21:00 AM10:53:00 PM0.813888889
22Angelica JohnsonOperations2:41:00 PM10:04:00 AM-0.192361111
23Camellia MorrisMarketing2:20:00 PM11:57:00 AM-0.099305556
24Domenic PlantOperations8:55:00 AM12:02:00 AM-0.370138889
25Manuel JonesManagement9:13:00 PM7:09:00 PM-0.086111111
26Johnathan WoodOperations6:58:00 PM11:35:00 AM-0.307638889
27Sharon UpsdellIT11:05:00 AM2:49:00 PM0.155555556
28Barry HillMarketing8:26:00 AM5:03:00 PM0.359027778
29
Sheet1
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi, I used below and getting required result.

= Table.AddColumn(#"Changed Type2", "Date Difference", each Duration.Hours([#"Start-Time"]-[#"End-Time"]))

(See Screenshot)
 

Attachments

  • PowerQuery-DateDifference.JPG
    PowerQuery-DateDifference.JPG
    63.9 KB · Views: 13
Upvote 0
Under add columns make sure you use the Time Subtraction.

View attachment 40597

Thank you all, I am trying to do that but it is grayed out. I first clicked on Add Column tab in PowerQ then I click on Custom Column then I changed the name of the column and under Custom Column formula, I clicked on EndTime column and then entered - and then clicked on StartTime column and then clicked ok. When I should click on Time then Subtract? Thank you very much.
 
Upvote 0
  1. Select End Time column
  2. Ctrl + Select Start Time column
  3. Select Add Column on menu
  4. Select Time on the menu
  5. Select subtract on the Time drop down menu

1623418232613.png
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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