首页 > 解决方案 > 如何根据条件累积列

问题描述

我正在尝试浏览一个列表并标记父母,这样我就可以自己加入一个平面列表

ID  Type     Idx 
200 EPIC      0
201 Feature   1
202 Feature   2
203 Feature   3
204 EPIC      4
205 Feature   5
206 Feature   6


Prefeered result
ID  Type     Idx   Parent   
200 EPIC      0    200     
201 Feature   1    200
202 Feature   2    200
203 Feature   3    200
204 EPIC      4    204
205 Feature   5    204
206 Feature   6    204

我曾尝试制作自引用条件列,但那是不可能的,

#"Added Custom" = Table.AddColumn(#"Added Index", "Parent", each if [Work Item Type] = "Epic" then [ID] else #"Added Custom"{[Index]-1}[ID ]),

标签: powerqueryaccumulate

解决方案


添加自定义列。填写下来。假设数据在 Table1 中,有 2 列名为 ID 和 Type,则

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Parent", each if [Type]="EPIC" then [#"ID"] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Parent"})
in #"Filled Down"

推荐阅读