Excel:包含 1 和 0 的矩阵表

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

如果这是我的数据:

姓名 访问城市
安娜 洛杉矶
狮子座 纽约
狮子座 洛杉矶

如何在 Excel 中创建这样的表格(最好是数据透视表):

纽约 洛杉矶
安娜 0 1
狮子座 1 1

因此结果需要类似于矩阵表,其中 1 表示有人访问过该城市,0 表示一个人没有访问过。

excel powerquery data-analysis
1个回答
0
投票

您可以使用

POWER QUERY

尝试以下操作


let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Name", "City Visited"}, {{"Count", each _, type table [Name=text, City Visited=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1,1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Name", "City Visited", "Index"}, {"Name", "City Visited", "Index"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded Custom", List.Distinct(#"Expanded Custom"[#"City Visited"]), "City Visited", "Index", List.Count)
in
    #"Pivoted Column"


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