带条件的 Power Query Table.FillDown
Power Query Table.FillDown with condition
有没有办法根据条件填写table?
下面是我的 table 示例。我想根据 Contract 列填写 Date 列。比如合同不是GB开头的,就填写上一行的Date,否则留空。
Contract Date Role
01F001 3/7/2016 A
01F017 5/6/2016 A
GB0007 B
GB0007 B
LBCA09 2/29/2016 A
LBCA09 B
LBCA09 B
LBCA09 B
LBCA12 2/25/2016 A
LBCA12 B
这是我想要的最终数据
Contract Date Role
01F001 3/7/2016 A
01F017 5/6/2016 A
GB0007 B
GB0007 B
LBCA09 2/29/2016 A
LBCA09 2/29/2016 B
LBCA09 2/29/2016 B
LBCA09 2/29/2016 B
LBCA12 2/25/2016 A
LBCA12 2/25/2016 B
我试图在 Table.Filldown 函数之外添加一个 if 语句,但出现语法错误。
= if not Text.StartsWith([Contract],"GB") then Table.FillDown(#"Replaced Value",{"Date"})
感谢任何帮助!
您可以分多个步骤完成此操作。
- 向下填充 "Date" 列
- 添加不以"GB"开头的条件列,并从"Date"
中获取值
- 删除 "Date" 列
- 将 "Custom" 列重命名为 "Date"
您可以使用 Table.Partition。对此的修改适用于更复杂的情况。
MyFunc = (_) => if Text.StartsWith(_, "GB") then 1 else 0,
Partitioned = Table.Partition(YourTable, "Contract", 2, each MyFunc(_)),
DownFilled = Table.FillDown(Partitioned{0}, {"Date"}),
Result = Table.Combine({DownFilled, Partitioned{1}})
有没有办法根据条件填写table?
下面是我的 table 示例。我想根据 Contract 列填写 Date 列。比如合同不是GB开头的,就填写上一行的Date,否则留空。
Contract Date Role
01F001 3/7/2016 A
01F017 5/6/2016 A
GB0007 B
GB0007 B
LBCA09 2/29/2016 A
LBCA09 B
LBCA09 B
LBCA09 B
LBCA12 2/25/2016 A
LBCA12 B
这是我想要的最终数据
Contract Date Role
01F001 3/7/2016 A
01F017 5/6/2016 A
GB0007 B
GB0007 B
LBCA09 2/29/2016 A
LBCA09 2/29/2016 B
LBCA09 2/29/2016 B
LBCA09 2/29/2016 B
LBCA12 2/25/2016 A
LBCA12 2/25/2016 B
我试图在 Table.Filldown 函数之外添加一个 if 语句,但出现语法错误。
= if not Text.StartsWith([Contract],"GB") then Table.FillDown(#"Replaced Value",{"Date"})
感谢任何帮助!
您可以分多个步骤完成此操作。
- 向下填充 "Date" 列
- 添加不以"GB"开头的条件列,并从"Date" 中获取值
- 删除 "Date" 列
- 将 "Custom" 列重命名为 "Date"
您可以使用 Table.Partition。对此的修改适用于更复杂的情况。
MyFunc = (_) => if Text.StartsWith(_, "GB") then 1 else 0,
Partitioned = Table.Partition(YourTable, "Contract", 2, each MyFunc(_)),
DownFilled = Table.FillDown(Partitioned{0}, {"Date"}),
Result = Table.Combine({DownFilled, Partitioned{1}})