Excel append 具有公共(public)列重复条目的表

标签 excel append powerquery vlookup index-match

我想按我的 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/RangeFrom within sheet
  • 当 PQ UI 打开时,导航到 Home => Advanced Editor
  • 记下代码第 2 行中的表名称。
  • 将现有代码替换为 M码 下面
  • 将粘贴代码的第 2 行中的表名更改为您的“真实”表名
  • 检查任何评论,还有 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
    enter image description here
    结果
    enter image description here

    关于Excel append 具有公共(public)列重复条目的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71125996/

    相关文章:

    java - 如何使用apache POI在excel中绘制圆形

    c++ - 将指向类的指针 append 到 QList QList<Class* >

    json - MS Power 查询循环

    excel - Power Query - 计算组函数中列中的非空白

    vba - VBA 右键粘贴问题

    vba - 删除列中重复的单元格内容

    ruby - 我如何遍历一组数字,做一些加法并追加到数组?

    excel - 合并两个查询而不在 Power Query 中重复行

    python - Python 中两个嵌套字符串列表之间的减法

    c# - 如何在 Windows Phone 8 中异步 append 文件