创建来自多个表格的摘要表格 Power BI

huangapple go评论82阅读模式
英文:

Create summary table from many tables Power BI

问题

Table 1- True | 7 | 5 |
Table 1 -False | 8 | 9 |
Table 2- True | 4 | 15 |
Table 2 -False | 11 | 9 |

英文:

I have many tables and from that, I need to create a summary table.

Table 1 -

IDs PSC id PSC ACV id ACV
A3 True 2 False 4
A4 True 3 True 1
A5 False 4 False 4
A6 False 5 True 6

Table 2 -

IDs PSC id PSC ACV id ACV
A5 True 12 False 7
A6 True 3 True 3
A7 False 4 False 4
A9 False 5 True 1

The summary table should be like this (summation of all True and Summation of all False )

Table ACV PSC
Table 1- True 7 5
Table 1 -False 8 9
Table 2- True 4 15
Table 2 -False 11 9

答案1

得分: 1

这不太简单 - 也许Ron或Horseyride有更好的想法。

向每个表格添加一个自定义列,列名为表格名称。例如:

表格 1:

表格 2:

追加查询如下:

追加的表格:

按照以下方式分组:

添加一个自定义列:

List.Sum( Table.SelectRows(Source, (x)=> x[Custom] = [Custom] and x[ACV id] = [PSC id])[ACV])

最终结果:

英文:

This isn't straightforward - maybe Ron or Horseyride have better ideas.

Add a custom column to each table with the table name. e.g.
创建来自多个表格的摘要表格 Power BI

Table 1:

创建来自多个表格的摘要表格 Power BI

Table 2:

创建来自多个表格的摘要表格 Power BI

Append queries as new:

创建来自多个表格的摘要表格 Power BI

Appended table:

创建来自多个表格的摘要表格 Power BI

Group exactly as follows:

创建来自多个表格的摘要表格 Power BI

创建来自多个表格的摘要表格 Power BI

Add a custom column:

创建来自多个表格的摘要表格 Power BI

List.Sum( Table.SelectRows(Source, (x)=> x[Custom] = [Custom] and x[ACV id] = [PSC id])[ACV])

Final result:

创建来自多个表格的摘要表格 Power BI

答案2

得分: 0

以下是已翻译的代码部分:

// 假定要合并的所有表格都以 "Table" 开头,并且是唯一的查询
let Source = Table.SelectRows(Record.ToTable(#sections[Section1]), each Text.StartsWith([Name], "Table")),
    List = List.Union(List.Transform(Source[Value], each Table.ColumnNames(_))),
    #"Expanded Data" = Table.ExpandTableColumn(Source, "Value", List, List),
    Combined = Table.AddColumn(Table.RenameColumns(Table.SelectColumns(#"Expanded Data",{"Name", "PSC id", "PSC"}),{{"PSC id", "id"}, {"PSC", "value"}}), "Type", each "PSC")
             & Table.AddColumn(Table.RenameColumns(Table.SelectColumns(#"Expanded Data",{"Name", "ACV id", "ACV"}),{{"ACV id", "id"}, {"ACV", "value"}}), "Type", each "ACV"),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(Combined, {{"id", type text}}, "en-US"),{"Name", "id"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Type]), "Type", "value", List.Sum)
    in #"Pivoted Column"

请注意,我已将HTML实体编码 " 替换为双引号 ", 以使代码更易阅读。

英文:

Alternate version that does NOT require adjusting the initial tables at all

// assumes all table to combine start with Table and are the only queries to do so
let Source =  Table.SelectRows(Record.ToTable(#sections[Section1]), each Text.StartsWith([Name], "Table")),
List = List.Union(List.Transform(Source[Value], each Table.ColumnNames(_))),
#"Expanded Data" = Table.ExpandTableColumn(Source, "Value", List,List),
Combined =  Table.AddColumn(Table.RenameColumns(Table.SelectColumns(#"Expanded Data",{"Name", "PSC id", "PSC"}),{{"PSC id", "id"}, {"PSC", "value"}}), "Type", each "PSC")
&  Table.AddColumn(Table.RenameColumns(Table.SelectColumns(#"Expanded Data",{"Name", "ACV id", "ACV"}),{{"ACV id", "id"}, {"ACV", "value"}}), "Type", each "ACV"),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(Combined, {{"id", type text}}, "en-US"),{"Name", "id"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"Merged"),
#"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Type]), "Type", "value", List.Sum)
in  #"Pivoted Column"

huangapple
  • 本文由 发表于 2023年7月7日 04:57:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632489.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定