Power Query - 分组依据、文本组合列表不同和连接文本

问题描述 投票:0回答:2

我是 Excel 中的 Power Query 新手,想要应用许多不同的函数来实现我的目标表,但我不确定如何将它们组合在一起的语法..

我想离开这里...

对此..

我开始使用以下步骤;

  • 选择输入表范围(整个蓝色数据集)
  • 选择变换
  • 选择分组依据 -> 池 ID,以及目标
  • 然后,我按照下面的屏幕截图和公式更新公式,但对于其中一列,返回的值是“错误”,如屏幕截图所示,并且无法想象为什么。当我打开错误时,它显示:

Expression.Error:找不到表的“单一 ID”列。 细节: 单一ID

公式作为文本...

= Table.Group(#"Changed Type", {"pooled ID", "Target"}, {
     {"Targets Combined", each Text.Combine([Target], "; "), type text}, 
     {"Single IDs Combined", each Text.Combine([single ID], "; "), type text}, 
     {"single ID Count", each Table.RowCount(_), Int64.Type}}) 

我还想介绍最后一列并按照绿色示例重命名标题,但更改标题时出现错误。

如有任何建议,我们将不胜感激!

powerquery m
2个回答
0
投票

您的代码中有两个小错误:

  1. 您使用了本应为
    [Single]
    的列名称
    [single ID]
  2. 您也不需要按
    "Target"
    进行分组:

当我像这样更改你的代码时,它应该会产生所需的结果:

let
  Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKsjPz1EwVNJRCkksSk8tUXAEMosz89JzUoHMWB28CpwIKXBGKDBCKHBCKHAhpMAVocAYocAZocANocAEocAFocCdkAIPpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"pooled ID" = _t, Target = _t, #"single ID" = _t]),
  Types = Table.TransformColumnTypes(Source, {{"pooled ID", type text}, {"Target", type text}, {"single ID", type text}}),
  Grouped = Table.Group(
    Types, 
    {"pooled ID"}, 
    {
      {"Target", each Text.Combine([Target], "; "), type text}, 
      {"single ID", each Text.Combine([single ID], "; "), type text}, 
      {"single ID Count", each Table.RowCount(_), Int64.Type}
    }
  ),
  UniqueTarget = Table.AddColumn(Grouped, "Unique Target", each List.First(List.Distinct(Text.Split([Target], "; "))), type text)
in
  UniqueTarget


0
投票

很棒的答案@chrimaho,

我正在尝试使其动态化,在 Access Analytics 中发现了问题,并希望获得帮助以实现理想的场景。

let
    Source = Excel.CurrentWorkbook(){[Name="tblData"]}[Content],
    Types = Table.TransformColumnTypes(Source, {{"Client ID#", type text}, {"System 1 contact ID", type text}, {"System 2 contact ID", type text}, {"System 3 contact ID", type text}, {"Name", type text}, {"Email", type text}, {"Phone number", type text}, {"Deal ID#s", type text}}),
    Grouped = Table.Group(
    Types, 
    {"Client ID#"}, 
    {
      {"System 1 contact ID", each Text.Combine( List.Distinct( [System 1 contact ID] ), ", "), type text},
      {"System 2 contact ID", each Text.Combine( List.Distinct( [System 2 contact ID] ), ", "), type text},
      {"System 3 contact ID", each Text.Combine( List.Distinct( [System 3 contact ID] ), ", "), type text},
      {"Name", each Text.Combine( List.Distinct( [Name] ), ", "), type text},
      {"Email", each Text.Combine( List.Distinct( [Email] ), ", "), type text},
      {"Phone number", each Text.Combine( List.Distinct( [#"Phone number"] ), ", "), type text},
      {"Deal ID#s", each Text.Combine( List.Distinct( [#"Deal ID#s"] ), ", "), type text}
    }
  )
in
  Grouped

目前我正在学习编辑高级编辑器,到目前为止我正处于使用“添加自定义列”的过渡阶段,并且类型处理对我来说仍然很难掌握。

let
    Source = Excel.CurrentWorkbook(){[Name="tblData"]}[Content],
    Grouped = Table.Group(
    Source, 
    {"Client ID#"}, 
    {
      {Table.ColumnNames(Source), each Text.Combine( List.Distinct( [_] ), ", "), type text}
    }
  )
in
  Grouped

Expression.Error:我们无法将 List 类型的值转换为 Text 类型。 细节: 值=[列表] 类型=[类型]

© www.soinside.com 2019 - 2024. All rights reserved.