Excel:按列查找和排序匹配项

伊利亚

我目前正在处理带有多个Excel文件的庞大的流行病学数据集。这些文件包含将近3万名患者的病理和临床报告。每个患者可以有几种病理和临床报告。为患者分配了唯一的ID。

我想将所有文件合并为一个,以便患者X001的ID包含所有文件的所有信息。我不能仅复制/粘贴文件,因为文件中的行数(ID)有所不同。

这是我要完成的示例。

我要合并两个列表,如下所示。

如您所见,List1和List 2的行号有所不同。另外,list1中有一些ID在list2中找不到,反之亦然。

我要合并它们,以便它们对齐和匹配,请参见下图。有人可以为此提供代码吗?我不能手动执行此操作,因为我在list1中有10万行,在list2中有30k行...要花几周的时间才能避免出错。

在此处输入图片说明

史蒂文·庞庞尼奥

您可以合并使用Power Query中内置的Excel合并的表,可以在“数据”选项卡下找到该表。

注意:照片是从Excel 2016拍摄的

第一步是创建查询:

  • 在“数据”下的获取和转换”部分中,单击-> ->,然后选择包含要合并表的适当工作簿。New QueryFrom FileFrom Workbook在此处输入图片说明
  • 选择在其中找到表的适当工作表,并确认它们正确显示
    • If you notice that the table is not correct, you can make changes to it via the Edit button below.
      • For example, if you notice that your Column headers are being treated as a normal value, you can click Use First Row as Headers under the Power Query Editor Home -> Transform
      • I would also recommend changing the name of the query so it makes more sense down the line
  • Once you are happy with the way the query is looking, click on the Close and Load Dropdown menu under the Power Query Editor Home and select Close and Load To...
    • Select Only Create Connection to add it into your Workbook Queries without duplicating the table. 在此处输入图片说明
  • Repeat the above steps for each table in which you are looking to merge.

Once you have all of your tables linked via Queries, you can now move on to merging them:

  • Under the same section of New Query select Combine Queries -> Merge 在此处输入图片说明
  • Select the two queries you are looking to merge in each of the respective boxes
    • Confirm that they are correct via the preview window (don't worry if not all rows show)
    • Rule of thumb would also be to select your largest query first, and the smaller second
  • Next, highlight the columns in which you are looking to merge based on. For your example it would be the ID. This is done simply by clicking on the column within the preview
  • Finally change the Join Kind to Full Outer and click OK 在此处输入图片说明

From here you should be back in the Power Query Editor

  • The final steps are modifying this merged query to your desired output
  • You should notice that there is a new column added next to your first original table with the name of the query at the top, next to the name is a button that allows you to expand out this query.在此处输入图片说明
  • Select the appropriate columns you would like to merge into the other table and click OK
  • If at any point you make a mistake, you can retrace your changes under Applied Steps within the Query Settings Pane
  • Once you are happy with the way your newly merged query looks, go ahead and click on Close and Load
  • Your should now have access to your new merged query that will update based on changes made to the original connected files
  • 如果您要从现在开始进行任何其他更改,只需单击表内的任意位置,您应该会看到“表工具”和“查询工具”选项卡都显示在顶部

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Microsoft Excel查找匹配项,无需对数据进行排序

来自分类Dev

Excel - 多列查找和匹配

来自分类Dev

通过查找列不列之间的匹配项和迭代

来自分类Dev

Excel-按多个匹配项对单元格进行排序

来自分类Dev

使用Excel VBA查找列匹配项并基于其他两个列的值合并

来自分类Dev

循环遍历列以查找匹配项 - VBA

来自分类Dev

匹配多列时查找重复项

来自分类Dev

按索引和列排序

来自分类Dev

使用excel中的内置函数查找列中的最后一个匹配项

来自分类Dev

Excel-查找列之间的匹配项,但复制其他单元格

来自分类Dev

按Q()或匹配项的数量对Django查询结果进行排序

来自分类Dev

按数据框进行分组和排序,然后根据条件找到第一个匹配项

来自分类Dev

使用匹配项按指定时区的日期查找文档

来自分类Dev

Excel 默认按列查找,而不是按行查找

来自分类Dev

MySQL按列和列值排序

来自分类Dev

Excel vba 按第 n 行排序并删除重复项

来自分类Dev

VBA Excel按特定列的排序范围

来自分类Dev

按IP地址对Excel列进行排序

来自分类Dev

在Excel VBA中按列排序

来自分类Dev

按特定列号排序 - Excel VBA

来自分类Dev

Excel函数按行查找和计算所有重复项,不包括第一个实例

来自分类Dev

Excel:从矩阵“方案”中查找正确的匹配项

来自分类Dev

Excel公式查找第二个匹配项

来自分类Dev

在两个 excel 列上查找匹配项

来自分类Dev

在 Excel 列表中查找第 n 个匹配项

来自分类Dev

Vlookup查找匹配项

来自分类Dev

Excel表查找匹配两列的值

来自分类Dev

如何在数据集中查找和排序重复项

来自分类Dev

如何按列排序和打破平局