MS Power Query – 消除一组分隔string中的重复项

我有Excel数据,看起来像这样:

Sources Targets Routes Lemons Chair A,D Lemons Chair D,F Oranges Chair B,F,G Oranges Chair B,C Oranges Door A,G Oranges Door B,C 

我正在尝试使用Power Query将其浓缩到:

 Sources Targets Routes Lemons Chair A,D,F Oranges Chair B,C,F,G Oranges Door A,B,C,G 

也就是说,对于每个源/目标对,我需要

  • 拆分逗号分隔的路线,
  • 消除重复的路线
  • 将路线组合回逗号分隔的列表
  • 将其显示在源/目标对的单个logging中。

路由源数据中最多有3条路由。 我很确定我需要将Routes列分成3列,然后使用Group 。 但在那里,我卡住了。

build议?

下面的代码实现了您所概述的步骤以及对路由的sorting。 它不使用拆分列,而是使用Text.Split。

SplittedRoutes步骤是使用Transform选项卡上的某些文本转换function创build的,然后调整为使用Text.Split。

同样,GroupedRows步骤是在“变换”选项卡上使用“分组依据”创build的,使用“所有行”操作,然后调整为以下代码。

 let Source = ExcelData, SplittedRoutes = Table.TransformColumns(Source,{{"Routes", each Text.Split(_,",")}}), ExpandedRoutes = Table.ExpandListColumn(SplittedRoutes, "Routes"), RemovedDuplicates = Table.Distinct(ExpandedRoutes, {"Sources", "Targets", "Routes"}), GroupedRows = Table.Group(RemovedDuplicates, {"Sources", "Targets"}, {{"Routes", each Text.Combine(List.Sort(_[Routes]),","), type text}}) in GroupedRows