Power Query Comparing Dates and returning late, early, or on time in a custom column

SteynBS

Board Regular
Joined
Jun 27, 2022
Messages
111
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I need some assistance as I am fairly new to power query.

I have 2 columns with dates Posting Date(Delivery Date) and Calculated Delivery date. If the Posting date is before the calculated delivery date it should return a value in a custom column Stating "early". If the dates are the same it should state "on time" and if the posting date is later than the calculated date, it should return "late" Any assistance please?

I need some advice on adding working days (provided in a column) to a date provided in another column. I have used the Date.AddDays([PO Date],[Planned Delivery Time), but this is adding calendar days and not working days.

Any assistance will be highly appreciated. Thank you
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Using just the PQ Editor interface, using the Conditional Column in the Add Column tab turns this:
Book1
AB
1Posting DateDelivery Date
201/29/202301/17/2023
303/07/202303/08/2023
403/11/202302/02/2023
508/01/202308/01/2023
608/12/202302/10/2023
708/17/202308/17/2023
808/28/202305/27/2023
908/31/202307/13/2023
1011/20/202311/21/2023
1112/18/202310/15/2023
Sheet1
into this:
Book1
DEF
1Posting DateDelivery DateStatus
201/29/202301/17/2023Early
303/07/202303/08/2023Late
403/11/202302/02/2023Early
508/01/202308/01/2023On Time
608/12/202302/10/2023Early
708/17/202308/17/2023On Time
808/28/202305/27/2023Early
908/31/202307/13/2023Early
1011/20/202311/21/2023Late
1112/18/202310/15/2023Early
Sheet1

M Code:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Dates"]}[Content],
    ChangedType = Table.TransformColumnTypes(Source,{{"Posting Date", type date}, {"Delivery Date", type date}}),
    AddedStatusColumn = Table.AddColumn(ChangedType, "Status", each if [Delivery Date] < [Posting Date] then "Early" else if [Delivery Date] = [Posting Date] then "On Time" else if [Delivery Date] > [Posting Date] then "Late" else null),
    ChangedType1 = Table.TransformColumnTypes(AddedStatusColumn,{{"Status", type text}})
in
    ChangedType1
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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