适用于POWER BI(DAX)中分组的ROWS的DISTINCT

时间:2019-10-09 07:55:00

标签: group-by powerbi combinations distinct dax

我有一张桌子

  

ID TYPES 1 A \\ 1 B \\ 2 B \\ 3 A \\ 4 A \\ 4 A \\ 4 A \\ 4 C \\ 4 D \\ 4 E \\ 5 B \\ 5 B \\ 6 A \\ 7 A \\ 7 B \\ 7 C \\ 8 B \\ 8 B \\ 9 D \\ 10 A \\ 10 A \\ 10 D

我有桌子:

  

ID TYPES
1 A+B \\ 2 B \\ 3 A \\ 4 A+A+A+C+D+E \\ 5 B+B \\ 6 A \\ 7 A+B+C \\ 8 B+B \\ 9 D \\ 10 A+A+D

它被用来: 让     源= Excel.Workbook(File.Contents(“ c:\ Desktop \ stac.xlsx”),null,true),     Sheet1_Sheet =源{[Item =“ Sheet1”,Kind =“ Sheet”]} [数据],     #“ Promoted Headers” = Table.PromoteHeaders(Sheet1_Sheet,[PromoteAllScalars = true]),     #“ Changed Type1” = Table.TransformColumnTypes(#“ Promoted Headers”,{{“ TYPE”,type text},{“ ID”,type text}}),     #“ Changed Type” = Table.TransformColumnTypes(#“ Changed Type1”,{{“ ID”,type text},{“ TYPE”,type text}}),     #“ Grouped Rows1” = Table.Group(#“更改类型”,{“ ID”},{{“所有行”,每个,类型表[ID = text,TYPE = text]}}),     #“ Added Custom” = Table.AddColumn(#“ Grouped Rows1”,“ Custom”,每个[All Rows] [TYPE]),     #“ Extracted Values” = Table.TransformColumns(#“ Added Custom”,{“ Custom”,每个Text.Combine(List.Transform(,Text.From),“ +”),键入text}),     #“已移除列” = Table.RemoveColumns(#“提取值”,{“所有行”}) 在     #“已删除的列”

但我需要区分不同的值:

  

ID TYPES
1 A+B \\ 2 B \\ 3 A \\ 4 A+C+D+E \\ 5 B \\ 6 A \\ 7 A+B+C \\ 8 B \\ 9 D \\ 10 A+D

1 个答案:

答案 0 :(得分:0)

第一步,按IDTypes在查询设计器中对表进行分组。所以你的桌子会变成这样

ID   Types
1     A         
1     B  
1     B         
2     B         
3     A        
4     A        
4     A         
4     A          

对此:

ID   Types
1     A         
1     B         
2     B         
3     A                
4     A   

然后应用与上面的代码相同的步骤,将不同类型组合到一栏中:

Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(, Text.From), "+"), type text})