根据年、半年、季度创建行
Create a row based on year, half yearly, quarter
我想将 table 动态扩展为以下内容:
基本上我想要实现的是 table 的每一行我都添加了基于开始(授予日期)和结束日期(归属结束日期)的归属任期类型的行).
我认为您的示例在日期方面有点偏差,但这适用于 powerquery。使用我的示例数据,将整个代码加载到主页...高级编辑器...以查看它在做什么。可能更改 Table1 以反映从 excel 加载的数据的名称 with data ... from table/range ...[x]headers
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Grant Date", type date}, {"Vesting tenure", type text}, {"Vesting Period", Int64.Type}, {"Vesting end date", type date}}),
#"Added Custom"= Table.AddColumn( #"Changed Type", "End Date",
each let
begin=[Grant Date],
end=[Vesting end date],
vtype=[Vesting tenure]
in
if vtype="Annually" then List.Generate(() => Date.AddYears(begin,1), each _ <= end, each Date.AddYears(_,1) )
else if vtype="Quarterly" then List.Generate(() => Date.AddQuarters(begin,1), each _ <= end, each Date.AddQuarters(_,1) )
else if vtype="Half Yearly" then List.Generate(() => Date.AddMonths(begin,6), each _ <= end, each Date.AddMonths(_,6) )
else null
),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "End Date"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"End Date", type date}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Start Date", each if [Vesting tenure]="Annually" then Date.AddYears([End Date],-1) else if [Vesting tenure]="Quarterly" then Date.AddQuarters([End Date],-1) else if [Vesting tenure]="Half Yearly" then Date.AddMonths([End Date],-6) else null, type date),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom1",{"Grant Date", "Vesting tenure", "Vesting Period", "Vesting end date", "Start Date", "End Date"})
in #"Reordered Columns"
如果需要,您可以在日期前后使用 Date.EndOfQuarter() 或 Date.EndOfMonth()
我想将 table 动态扩展为以下内容:
基本上我想要实现的是 table 的每一行我都添加了基于开始(授予日期)和结束日期(归属结束日期)的归属任期类型的行).
我认为您的示例在日期方面有点偏差,但这适用于 powerquery。使用我的示例数据,将整个代码加载到主页...高级编辑器...以查看它在做什么。可能更改 Table1 以反映从 excel 加载的数据的名称 with data ... from table/range ...[x]headers
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Grant Date", type date}, {"Vesting tenure", type text}, {"Vesting Period", Int64.Type}, {"Vesting end date", type date}}),
#"Added Custom"= Table.AddColumn( #"Changed Type", "End Date",
each let
begin=[Grant Date],
end=[Vesting end date],
vtype=[Vesting tenure]
in
if vtype="Annually" then List.Generate(() => Date.AddYears(begin,1), each _ <= end, each Date.AddYears(_,1) )
else if vtype="Quarterly" then List.Generate(() => Date.AddQuarters(begin,1), each _ <= end, each Date.AddQuarters(_,1) )
else if vtype="Half Yearly" then List.Generate(() => Date.AddMonths(begin,6), each _ <= end, each Date.AddMonths(_,6) )
else null
),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "End Date"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"End Date", type date}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Start Date", each if [Vesting tenure]="Annually" then Date.AddYears([End Date],-1) else if [Vesting tenure]="Quarterly" then Date.AddQuarters([End Date],-1) else if [Vesting tenure]="Half Yearly" then Date.AddMonths([End Date],-6) else null, type date),
#"Reordered Columns" = Table.ReorderColumns(#"Added Custom1",{"Grant Date", "Vesting tenure", "Vesting Period", "Vesting end date", "Start Date", "End Date"})
in #"Reordered Columns"
如果需要,您可以在日期前后使用 Date.EndOfQuarter() 或 Date.EndOfMonth()