Calculating Retirement Date

chostett

New Member
Joined
Jan 24, 2018
Messages
2
Hello all, I'm trying to calculate expected retirement dates of aircraft. The calculation is dependent on the delivery date, aircraft status, status change date, and usage. I have spent the morning working on it and thought I had it setup correctly. However, I am getting the following error:

Expression.Error: We cannot convert the value #date(2006, 11, 30) to type List.
Details:
Value=11/30/2006
Type=Type

Basically, the retirement date will be approximately 25, 35, or 50 years after initial delivery. I've added some random numbers and a MAX for aircraft that should already be out of service, but are still flying. Note, I am new to M, but here is my attempt at the calculation:

Retirement Date=DateTime.Date(if ([Status]="Written off" or [Status]="Retired") then [Status Change Date] else List.Max(if [Primary Usage]="Passenger" then Date.AddYears([Delivery Date],25 + Number.Round(Number.RandomBetween(-5,10),0)) else if [Primary Usage]="Freight / Cargo" then Date.AddYears([Delivery Date],35 + Number.Round(Number.RandomBetween(-5,10),0)) else Date.AddYears([Delivery Date],50 + Number.Round(Number.RandomBetween(-5,10),0)),DateTime.Date(Date.AddMonths(DateTime.LocalNow(),Number.Round(Number.RandomBetween(1,120),0)))))

Can you please point me to what I am doing wrong here? I've got the formula worked out as an excel formula, but I want to be able to perform the calculation with Power Query, so I don't have to pull all of the fields needed for the calculation into my table to save space.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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