字符串的枢轴 table excel

Pivot table of strings excel

我比 excel 更精通 python/R 但这需要一个 excel 特定的解决方案,希望得到这里的指导!

我有一个excel,格式如下

worker id   person  question body   question answer
1   T   Q1  A1
1   T   Q2  A2
1   T   Q3  A3
1   T   Q4  A4
1   T   Q5  A5
2   A   Q1  A6
2   A   Q2  A7
2   A   Q3  A8
2   A   Q4  A9
2   A   Q5  A10
3   B   Q1  A11
3   B   Q2  A12
3   B   Q3  A13
3   B   Q4  A14
3   B   Q5  A15

我想要下面的结果

worker id   person  Q1  Q2  Q3  Q4  Q5
1   T   A1  A2  A3  A4  A5
2   A   A6  A7  A8  A9  A10
3   B   A11 A12 A13 A14 A15

我尝试使用普通数据透视表 table,其中 worker id 作为行,question body 作为列,question answer 作为数据,但它不起作用,因为这需要数字答案,但问题的答案是字符串。

有人能帮忙吗?

Power 查询:

  • 以问题列为中心
    • 无聚合

M码

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{
            {"worker id", Int64.Type}, {"Person", type text}, {"question body", type text}, {"answer", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", 
        List.Distinct(#"Changed Type"[#"question body"]), "question body", "answer")
in
    #"Pivoted Column"