gpt4 book ai didi

excel - 如何对 Power Query 中的 N 列求和

转载 作者:行者123 更新时间:2023-12-04 21:45:23 25 4
gpt4 key购买 nike

我的数据每个月都会更新,因此我正在尝试创建一个电源查询表,该表将显示我创建的旋转 (N) 列的总和,但我似乎无法弄清楚如何在电源查询中执行此操作。
我目前有这个代码:
enter image description here
enter image description here

最佳答案

  • 转后:
  • 创建要求和的列列表
  • 添加索引列以限制每一行
  • 添加一列,对仅该行的列求和
  • 删除索引列
  • let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month Yr", Date.Type}, {"Attribute", type text}, {"Value", Currency.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "MonthYear", each Date.ToText([Month Yr],"MMMM yyyy")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Month Yr"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[MonthYear]), "MonthYear", "Value", List.Sum),

    //NEW code added after your Pivoted Column line

    //Get List of columns to sum
    // Assumes this list all columns **except the first** in the Pivot table
    // There are other methods of generating this list if this assumption is incorrect
    colToSum = List.RemoveFirstN(Table.ColumnNames(#"Pivoted Column"),1),

    //Add Index Column
    IDX = Table.AddIndexColumn(#"Pivoted Column","Index",0,1),

    //Sum each row of "colToSum"
    totals = Table.AddColumn(IDX, "Sum", each List.Sum(
    Record.ToList(
    Table.SelectColumns(IDX,colToSum){[Index]})
    ), Currency.Type),
    #"Removed Columns1" = Table.RemoveColumns(totals,{"Index"})


    in
    #"Removed Columns1"
    enter image description here

    关于excel - 如何对 Power Query 中的 N 列求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67312962/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com