简体   繁体   中英

Combine two formulas in power query

Need to generate the end date based on Vesting type column

在此处输入图像描述

I am able to generate formulas to create the end date as per the below column在此处输入图像描述

I have been able to generate the formulas in power query in two separate tables for the same data using the codes below.

Graded vesting formula

let 
StDt = [#"Grant date #(lf)(dd/mm/yyyy)"],
end = [#"Vesting end date#(lf)(dd/mm/yyyy)"],
vType = [Vesting tenure]
in
if vType ="Annually" then List.Generate(() => Date.AddYears(StDt,1),each _ <= end,each Date.AddYears(_,1))
else if vType = "Quarterly" then List.Generate (() => Date.AddQuarters(StDt,1), each _ <=end, each Date.AddQuarters (_,1) )
else if vType="Half yearly" then List.Generate(() => Date.AddMonths (StDt,6), each _ <= end, each Date.AddMonths(_,6) )
else null

Bullet vesting

let 
Startdate= [#"Grant date #(lf)(dd/mm/yyyy)"],
Enddate = [End date],
Firstdate = Date.AddDays(Date.EndOfMonth(Startdate),1),
Lastdate = Date.StartOfMonth(Enddate),
ResultTemp = List.Generate(()=> [x=Firstdate], each [x] <= Lastdate, each[x=Date.AddMonths([x],1)], each [x]),
Result=List.Distinct({Startdate} & ResultTemp & {Enddate})
in
Result

I'm looking for a way to combine these two formulas in a single formula to update it in a single column.

The end objective is if it is graded vesting it should generate dates based on vesting tenure and if it is bullet vesting it should generate dates based on vesting end date column

You could use below code. Change column names as needed to include the line feeds

let 
StDt = [Grant date],
end = [Vesting end date],
vType = [Vesting tenure],
vType2 = [Vesting type],
Enddate = [End date],
Firstdate = Date.AddDays(Date.EndOfMonth(StDt),1),
Lastdate = Date.StartOfMonth(Enddate)
in
if vType2 ="Bullet vesting" then List.Distinct({StDt} & List.Generate(()=> [x=Firstdate], each [x] <= Lastdate, each[x=Date.AddMonths([x],1)], each [x])& {Enddate})
else if vType ="Annually" then List.Generate(() => Date.AddYears(StDt,1),each _ <= end,each Date.AddYears(_,1))
else if vType = "Quarterly" then List.Generate (() => Date.AddQuarters(StDt,1), each _ <=end, each Date.AddQuarters (_,1) )
else if vType="Half yearly" then List.Generate(() => Date.AddMonths (StDt,6), each _ <= end, each Date.AddMonths(_,6) )
else null)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM