【问题标题】:Categorize Columns in Power BI在 Power BI 中对列进行分类
【发布时间】:2021-12-04 05:06:56
【问题描述】:

我有一个数据集 (Excel),其中包含多年来客户满意度调查问卷的结果。

Excel 中的每个问题都是一列,每一行都是响应的值(值 1 到 5)。 但是,这些问题是按类别分开的(例如,关于“沟通”、“质量”的问题……)。 我想找到一种方法将这些列“分组”或“分类”成类别,但我无法理解它。这感觉像是与层次结构有关,但显然不是这样。

使用示例数据更新: Image of excel data

Quality performance Company perception Communication
Quality Q1 Quality Q2 Quality Q3 Company Q1 CompanyQ2 Response Time Correct Capable
Responder Quality Q1 Quality Q2 Quality Q3 Company Q1 CompanyQ2 Response Time Correct Capable
Client 1 0 0 5 0 5 1 2
Client 2 2 5 5 3 1 4 3
Client 3 5 1 3 5 4 3 3
Client 4 0 4 2 4 0 2 4
Client 5 0 1 5 2 3 0 5
Client 6 5 2 0 0 0 2 3
Client 7 2 1 4 1 1 2 3
Client 8 4 0 2 0 5 4 5
Client 9 2 0 2 1 1 0 5
Client 10 1 2 4 4 0 2 3
Client 11 2 4 5 4 3 0 0

在 PowerBI 上,我希望每个类别都有一个分数,我可以深入了解更深入的细节。

【问题讨论】:

  • 提供样本数据和预期输出
  • 已编辑数据截图。
  • 关注How To
  • 这与我将要模仿的表格一样接近

标签: powerbi powerbi-desktop


【解决方案1】:

你可以试试这个

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "ZZC7DoQgEEV/xVBbyMi+ar/AbY2FcSlIFIxisX+/qwzmisWEucPJnUfTiLdeJmc/eha5qNduMP6b1RIFoSj/onLj1FnGDkFBjKs1feeNs1mwXvTlo3LzrHsv2rwR1WC09dlmVXDc4N3qhCDthfC5RcmQ2nMAS3CIueL8BCpup9g56pADGOeS7EbsFmYF8A5AAUFp6wcX4wLy2DgBn8lc8Twqbf0CgMDxMqMsoJdK7E+9JVJ4xbBW2/4A",
          BinaryEncoding.Base64
        ),
        Compression.Deflate
      )
    ),
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [
        Column1 = _t,
        #"Quality performance" = _t,
        Column3 = _t,
        Column4 = _t,
        #"Company perception" = _t,
        Column6 = _t,
        Communication = _t,
        Column8 = _t
      ]
  ),
  ct = Table.TransformColumnTypes(
    Source,
    {
      {"Column1", type text},
      {"Quality performance", type text},
      {"Column3", type text},
      {"Column4", type text},
      {"Company perception", type text},
      {"Column6", type text},
      {"Communication", type text},
      {"Column8", type text}
    }
  ),
  DH = Table.DemoteHeaders(ct),
  CT = Table.TransformColumnTypes(
    DH,
    {
      {"Column1", type text},
      {"Column2", type text},
      {"Column3", type text},
      {"Column4", type text},
      {"Column5", type text},
      {"Column6", type text},
      {"Column7", type text},
      {"Column8", type text}
    }
  ),
  KFR = Table.FirstN(CT, 1),
  TT = Table.Transpose(KFR),
  AC = Table.AddColumn(
    TT,
    "Custom",
    each
      if [Column1] = "Column1" then
        ct[Column1]{0}
      else if Text.Contains([Column1], "Column") then
        null
      else
        [Column1]
  ),
  RTR = Table.Skip(AC, 1),
  FD = Table.FillDown(RTR, {"Custom"}),
  #"Promoted Headers" = Table.PromoteHeaders(ct, [PromoteAllScalars = true]),
  #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(
    #"Promoted Headers",
    {"Responder"},
    "Attribute",
    "Value"
  ),
  #"Grouped Rows" = Table.Group(
    #"Unpivoted Other Columns",
    {"Responder"},
    {{"ad", each _, type table [Responder = nullable text, Attribute = text, Value = text]}}
  ),
  #"Added Custom" = Table.AddColumn(
    #"Grouped Rows",
    "Custom",
    each
      let
        src = [ad],
        Index = Table.AddIndexColumn(src, "Index", 0, 1),
        Add = Table.AddColumn(Index, "Custom", each FD[Custom]{[Index]}),
        Remove = Table.RemoveColumns(Add, {"Index"}),
        #"Added Custom1" = Table.AddColumn(
          Remove,
          "Custom.1",
          each List.Difference(Text.Split([Attribute], " "), Text.Split([Custom], " "))
        ),
        #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
        #"Renamed Columns" = Table.RenameColumns(
          #"Expanded Custom.1",
          {{"Custom", "CAT"}, {"Custom.1", "SubCat"}}
        ),
        #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns", {"Attribute"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns", {{"Value", type number}})
      in
        #"Changed Type"
  ),
  #"Removed Other Columns" = Table.SelectColumns(#"Added Custom", {"Custom"}),
  #"Expanded Custom" = Table.ExpandTableColumn(
    #"Removed Other Columns",
    "Custom",
    {"Responder", "Value", "CAT", "SubCat"},
    {"Responder", "Value", "CAT", "SubCat"}
  )
in
  #"Expanded Custom"

【讨论】:

    【解决方案2】:

    我认为第一步是对您的表格进行反透视,以便按照此模式在每个项目中保留一行。 Microsoft Docs - Unpivot columns。将创建类似这样的代码:

    =Table.UnpivotOtherColumns(Source, {"Responder"}, "Question", "Response")
    

    然后您可以创建一个包含“问题”列和“组”的“问题”表。将问题表加入到问题的未透视表中,您现在可以报告您的问题和小组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 2021-09-09
      • 1970-01-01
      • 2018-06-21
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多