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.
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.