【问题标题】:Customized column power query editor - filters自定义列电源查询编辑器 - 过滤器
【发布时间】:2018-07-17 00:05:20
【问题描述】:

我正在尝试在 power query editor 中添加一列(使用 M,因为我想在表输出中显示新列)应该计算以下公式:

Value of recordMarket Value / 列之和 Market Value

但这个总和应该只包括另外两列(在我的情况下为 DateAccount number)等于我想要计算值的 record/row 中的值的行。

【问题讨论】:

    标签: powerquery


    【解决方案1】:

    据我所知,您正在尝试实现与在 Excel 表中但在电源查询中执行 SUMIFS() 计算相同的效果?

    这可以通过多种方式完成,但最简单的是使用电源查询的“分组依据”功能。使用此方法,您可以使用 Table.Group() 按两列(日期和帐号)对数据进行分组,并获取所有记录的总和。然后您需要做的就是通过逐步引用该组将该值合并到原始表中。这相当于使用数据透视表,然后在日期和帐号列上执行 VLOOKUP。

    这里是 M 代码:

    let
    // You're previous code here (replace the "Source" & #"Changed Type" lines)
        Source = Excel.CurrentWorkbook(){[Name="my_data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Account number", type text}, {"Market Value", type number}}),
    
    // Group by Date & Account Number to sum each record
        #"Calculate Record Value" = Table.Group(#"Changed Type", {"Date", "Account number"}, {{"Value of Record", each List.Sum([Market Value]), type number}}),        // Replace #"Changed Type" in this line with the last step reference from your code
    // Merge the group by value back to each record in the orginal table
        #"Merged Record Value" = Table.NestedJoin(#"Changed Type",{"Date", "Account number"},#"Calculate Record Value",{"Date", "Account number"},"sum",JoinKind.LeftOuter),
    // Expand your new column
        #"Expanded Record Value" = Table.ExpandTableColumn(#"Merged Record Value", "sum", {"Value of Record"}, {"Value of Record"})
    in
        #"Expanded Record Value"
    

    希望这会有所帮助! 如果我误解了您的问题或者此解决方案对您不起作用,请告诉我。

    最好的问候 道格C

    【讨论】:

    • 非常感谢您的回复!受到您的建议的启发,并将尝试实施。
    猜你喜欢
    • 2021-05-17
    • 2020-07-29
    • 2010-10-14
    • 1970-01-01
    • 2016-09-11
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    相关资源
    最近更新 更多