我想按我的 ID 列组合两个表。两个表都有重复的 ID 值。
表格1:
ID Reminder_date Type
119128 05-Jan Pear
11601368 07-Jan Apple
119128 05-Jan Apple
8445018 04-Jan Pear
11601368 05-Jan Grape
119128 04-Jan Pear
11601368 14-Jan Grape
5688401 14-Jan Grape
119128 11-Jan Pear
11601368 21-Jan Pear
11045680 11-Jan Orange
表 2:ID Purchase_date
11601368 12-Jan
11601368 13-Jan
11601368 11-Jan
119128 11-Jan
119128 29-Jan
8445018 24-Jan
8445018 11-Jan
5688401 28-Jan
11045680 10-Jan
我不能使用两列来使用索引匹配,因为它们没有两个公共(public)列,我希望在我的最终表中有更多行。最终我想要:
ID Reminder_date Type Purchase_date
119128 05-Jan Pear 11-Jan
119128 05-Jan Pear 29-Jan
11601368 07-Jan Apple 12-Jan
11601368 07-Jan Apple 13-Jan
11601368 07-Jan Apple 11-Jan
119128 05-Jan Apple 11-Jan
119128 05-Jan Apple 29-Jan
8445018 04-Jan Pear 24-Jan
8445018 04-Jan Pear 11-Jan
11601368 05-Jan Grape 12-Jan
11601368 05-Jan Grape 13-Jan
11601368 05-Jan Grape 11-Jan
119128 04-Jan Pear 11-Jan
119128 04-Jan Pear 29-Jan
11601368 14-Jan Grape 11-Jan
11601368 14-Jan Grape 13-Jan
11601368 14-Jan Grape 12-Jan
5688401 14-Jan Grape 28-Jan
119128 11-Jan Pear 11-Jan
119128 11-Jan Pear 29-Jan
11601368 21-Jan Pear 12-Jan
11601368 21-Jan Pear 13-Jan
11601368 21-Jan Pear 11-Jan
11045680 11-Jan Orange 10-Jan
11601368 12 个条目,119128 8 个条目,8445018 2 个条目,5688401 1 个条目,11045680 1 个条目
最佳答案
您可以使用 Power Query
获得所需的输出。 , 在 Windows Excel 2010+ 和 Office 365 Excel 中可用
Data => Get&Transform => From Table/Range
或 From within sheet
Home => Advanced Editor
Applied Steps
窗口,更好地理解算法和步骤M码
let
//Be sure to change table name in Source lines to actual name in your workbook
//Read in Table 1 and set data types
Source = Excel.CurrentWorkbook(){[Name="Tbl_1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Reminder_date", type date}, {"Type", type text}}),
//Add Index column to retain sort order
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
//Read in Table 2 and set data types
Source1 = Excel.CurrentWorkbook(){[Name="Tbl_2"]}[Content],
#"Changed Type1" = Table.TransformColumnTypes(Source1,{{"ID", Int64.Type}, {"Purchase_date", type date}}),
//Join the tables with a FullOuter join
joined = Table.NestedJoin(#"Added Index","ID",#"Changed Type1","ID","Joined",JoinKind.FullOuter),
//resort to original order
//then delete index column
#"Sorted Rows" = Table.Sort(joined,{{"Index", Order.Ascending}}),
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"}),
//expand the Purchase date column
#"Expanded Joined" = Table.ExpandTableColumn(#"Removed Columns", "Joined", {"Purchase_date"}, {"Purchase_date"})
in
#"Expanded Joined"
Tbl_1 & Tbl_2 结果
关于Excel append 具有公共(public)列重复条目的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71125996/