我的数据集
数据集位于 Excel 中。我有一列包含唯一 ID、一些超出此问题范围的数据,以及一个基于这些数据返回 true 或 false 的“if”条件。第一个 true/false 为 Null,因为它评估前一行的数据以确定布尔值。
ID boolean
15032 null
25638 false
45035 false
55139 true
15235 true
14550 false
15035 false
13035 false
12235 true
所需输出
添加名为 ConditionalIncremental 的列。从 1 开始,仅当该行的布尔值等于 TRUE 时才递增,否则与前一行保持相同。
ID boolean ConditionalIncremental
15032 null 1
25638 false 1
45035 false 1
55139 true 2
15235 true 3
14550 false 3
15035 false 3
13035 false 3
12235 true 4
基本上;如果 boolean = true 则前一行 + 1 否则前一行。
我发现了什么
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"boolean", type logical}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each
let a = Table.SelectRows(#"Added Index",(x)=> x[Index] <= [Index]),
b = a[boolean],
c = List.RemoveItems(b, {false, null})
in List.Count(c)+1
)
in
#"Added Custom"
添加列..索引列...
添加列...自定义列...
= 1+List.Sum(List.Transform(List.FirstN(#"Added Index"[boolean],1+[Index]), each if _=true then 1 else 0))