Excel 用公共列的重复条目追加表
Excel apend tables with duplicate entries of common column
我想通过我的 ID 列合并两个 table。两个 table 都有重复的 ID 值。
Table 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
Table 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
我不能使用两列索引匹配,因为它们没有两个公共列,我希望在我的最终 table.
中有更多行
最终我想要:
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
中可用
- Select 你原来的一些单元格 table
Data => Get&Transform => From Table/Range
或 From within sheet
- 当 PQ UI 打开时,导航到
Home => Advanced Editor
- 记下代码第 2 行中的 Table 名称。
- 将现有代码替换为下面的M-Code
- 将粘贴代码第 2 行中的 table 名称更改为您的“真实”table 名称
- 检查任何评论,以及
Applied Steps
window,以更好地理解算法和步骤
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
结果
我想通过我的 ID 列合并两个 table。两个 table 都有重复的 ID 值。
Table 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
Table 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
我不能使用两列索引匹配,因为它们没有两个公共列,我希望在我的最终 table.
中有更多行最终我想要:
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
- Select 你原来的一些单元格 table
Data => Get&Transform => From Table/Range
或From within sheet
- 当 PQ UI 打开时,导航到
Home => Advanced Editor
- 记下代码第 2 行中的 Table 名称。
- 将现有代码替换为下面的M-Code
- 将粘贴代码第 2 行中的 table 名称更改为您的“真实”table 名称
- 检查任何评论,以及
Applied Steps
window,以更好地理解算法和步骤
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
结果