据我所知,您正在尝试实现与在 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