Sum column based on criteria while grouping in Power Query

时间:2018-02-01 18:38:04

标签: excel powerbi powerquery m

I am trying to group a datasheet and return the sum of column a based on values in column b but I still need to return the sum of the complete column c so I can't filter the table prior to grouping. I just tried this:

Table.Group ( MyTable , { "ColumnD" } , { { "Sum Criteria" , each List.Sum ( Table.Column ( Table.SelectRows ( _ , each [ColumnB] = "Foo" ) , "ColumnA" ) ) , Int64.Type } , { "Sum Complete" , each List.Sum ( [ColumnC] ) , type number } } ) But the numbers aren't right, in my example the result of the criteria based column should be 15 but it's returning 35.

Can anyone please help me figure out where I am erring?

Thanks

1 个答案:

答案 0 :(得分:2)

我很抱歉提出这个问题,我最初使用的解决方案是正确的。 我的错误是我通过添加包含所有行的另一列来预览结果,当我预览它时,我将它们计算出来并发现这些数字并不匹配。当我扩展表格时,显示更多行显示公式是准确的。

我想知道查询设计器的错误是什么,它在预览表时没有显示所有行。

我要离开这个问题,以便其他人可以看到我的公式并享受它。