How to remove duplicate values in one column and concatenate values from another column where removal happens?

情到浓时终转凉″ 提交于 2020-06-17 09:46:40

问题


The Data:

ACCOUNT       DESC   
Gallup        1 
Gallup        2
Phoenix       2
Red Rock      1
Red Rock      2 
Albuquerque   1

The desired output:

ACCOUNT       DESC   
Gallup        1,2
Phoenix       2
Red Rock      1,2
Albuquerque   1

but in a general scope as this is a small subset (Many other accounts, 100+)

Is there a way to remove duplicate values of "ACCOUNT" and to concatenate values from the removed duplicates where the "ACCOUNT" matched?? (this method is the preferred approach desired if possible)


回答1:


Right click Account column, Group By

use New Column name : Data, Operation: All Rows,

Add Column, Custom Column, formula

=Table.Column([Data],"DESC")  

Click on arrows at top of new column, extract value, use comma delimiter

Remove extra column

Full sample code if data was in Table1:

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"ACCOUNT"}, {{"Data", each _, type table}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Column([Data],"DESC")),
#"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
#"Removed Columns" = Table.RemoveColumns(#"Extracted Values",{"Data"})
in #"Removed Columns"


来源:https://stackoverflow.com/questions/62268926/how-to-remove-duplicate-values-in-one-column-and-concatenate-values-from-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!