bug_x

导航

 

方法一:

    

let
    源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
    更改的类型 = Table.TransformColumnTypes(源,{{"name", type text}, {"name_v", Int64.Type}}),
    n1 =   Table.AddColumn(更改的类型,"c1",each List.Sum(Table.SelectRows(更改的类型,  (x)=>x[name_v]<=_[name_v])[name_v]))
in
    n1

  

解析:由内到外
Table.SelectRows(更改的类型,(x)=>x[name_v]<=_[name_v])[name_v]   
      Table.SelectRows(更改的类型,(x)=>x[name_v]<=_[name_v])  返回的是一行 包含name ,name_v 两列
      (x)=>x[name_v]<=_[name_v] #定义一个函数(),参数是x ( 包含name ,name_v 两列), 函数计算方式:x[name_v]<=_[name_v]
          _[name_v]  ### 对每一行的列name_v 都递归重复一遍

  

List.Sum()
Table.SelectRows(更改的类型,(x)=>x[name_v]<=_[name_v])[name_v]


方法二:
let
    源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
    更改的类型 = Table.TransformColumnTypes(源,{{"name", type text}, {"name_v", Int64.Type}}),
    n1 =   Table.AddColumn(更改的类型,"c1",each Table.SelectRows(更改的类型,  (x)=>x[name_v]<=_[name_v])),
    #"聚合的 c1" = Table.AggregateTableColumn(n1, "c1", {{"name_v", List.Sum, "c1.name_v 的总和"}})
in
    #"聚合的 c1"
= Table.AddColumn(源, "累计", each Table.SelectRows(源,(x)=>x[索引]<=_[索引]))
= Table.AddColumn(源, "累计", (x)=> Table.SelectRows(源,each _[索引]<=x[索引]))
= Table.AddColumn(源, "累计", (x)=> Table.SelectRows(源,(y)=>y[索引]<=x[索引]))

  

posted on 2022-02-26 11:54  bug_x  阅读(119)  评论(0编辑  收藏  举报