如何在EXCEL POWER查询中增加合计行? [英] How to add totals row to excel power query?

查看:34
本文介绍了如何在EXCEL POWER查询中增加合计行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在EXCEL POWER查询中使用‘GROUP’函数生成了如下表

score 1 score 2 score 3
A   6   25  50
B   8   30  20
C   15  15  30
D   20  0   10

我想添加一个合计行(相当于普通数据透视表中的"显示列的合计"),因此结果将如下所示

score 1 score 2 score 3
A   6   25  50
B   8   30  20
C   15  15  30
D   20  0   10
Total 49    70      110

有没有人知道有没有简单的方法可以做到这一点?谢谢您,RY

推荐答案

另一种方式:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    group = Table.Group(Source, {}, {{"letter", each "Total"},
                                     {"score 1", each List.Sum([score 1])},
                                     {"score 2", each List.Sum([score 2])}, 
                                     {"score 3", each List.Sum([score 3])}}),
    append = Table.Combine({Source, group})
in
    append

或:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    cols = Table.ColumnNames(Source),
    group = Table.Group(Source, {}, List.Zip({cols, {each "Total"}&
                                    List.Transform(List.Skip(cols), 
                                    (x)=>each List.Sum(Table.Column(_,x)))})),
    append = Table.Combine({Source, group})
in
    append

或:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    group = Table.Group(Source, {}, List.TransformMany(Table.ColumnNames(Source),
                                    (x)=>{each if x = "letter" then "Total" 
                                    else List.Sum(Table.Column(_,x))}, (x,y)=>{x,y})),
    append = Table.Combine({Source, group})
in
    append

这篇关于如何在EXCEL POWER查询中增加合计行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆