根据公共/键列映射两个列

发布于 2025-02-12 21:42:35 字数 1262 浏览 0 评论 0原文

如下所示,

此纸提供了类型和产品

类型产品
XMAS_GREENXMAS TREE
XMAS_REDXMAS
XMAS_REDTREEX
XMAS_MAS_BLUEbunny bunny
bunny_bluebunny

un

TREEBUNNY_RED BUNNY
XMAS TREE XMAS我有两张纸, Ltd
BunnyBunny Corp Ltd

使用上面的床单,我想生成另一张床单,显示给供应商映射的类型(基于产品)

类型供应商
XMAS_GREENXMAS CORP
XMAS_RED XMAS_REDXMAS_MAS_MAS_BLUE
BUNNY_REDXMAS CORP LTD
BUNNY_REDCORP LTD
BUNNY_BLUEBUNNY CORP LTD

到目前为止,我一直在尝试使用VSookup来匹配列表,但期望它可以使用1:1映射来工作。我正在尝试的另一种方法是对product进行计数重复,并基于product count 供应商。可以使用这需要扩大6000多种记录,并且可以使用VBA宏。这是在2016年。我不是高级Excel用户,并且对正确方向的任何帮助都非常感谢。

I have two sheets as shown below

This sheet provides a mapping between type and product

TypeProduct
Xmas_GreenXmas Tree
Xmas_RedXmas Tree
Xmas_BlueXmas Tree
Bunny_RedBunny
Bunny_BlueBunny

and the another sheet provides mapping between products and vendor as shown below

ProductVendor
Xmas TreeXmas Corp Ltd
BunnyBunny Corp Ltd

Using the above sheets, I want to generate another sheet showing type to vendor mapping (based on product)

TypeVendor
Xmas_GreenXmas Corp Ltd
Xmas_RedXmas Corp Ltd
Xmas_BlueXmas Corp Ltd
Bunny_RedBunny Corp Ltd
Bunny_BlueBunny Corp Ltd

So far I have tried to use VSLOOKUP to match tables based on column but it expects 1:1 mapping to work. Another approach I'm trying is to count duplicates on Product and duplicate the Vendor based on Product count. This needs to scale up for 6000+ records and VBA macros can be used. This is on 2016. I'm not an advanced Excel user and any help in the right direction is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

标点 2025-02-19 21:42:35

有几种方法可以做到这一点。 Xlookup()可能最合适。

=XLOOKUP(XLOOKUP(B10,$A$2:$A$6,$B$2:$B$6,""),$D$2:$D$6,$E$2:$E$6,"")

如果您在 excel-2016 上,则可以使用index/match like-

=INDEX($E$2:$E$6,MATCH(INDEX($B$2:$B$6,MATCH(B10,$A$2:$A$6,0)),$D$2:$D$6,0))

with vlookup()可以尝试 -

=VLOOKUP(VLOOKUP(B10,$A$2:$B$6,2,FALSE),$D$2:$E$6,2,FALSE)

最新版本的 Microsoft-365 可以使用byrow()一个GO。

=BYROW(B10:B14,LAMBDA(x,XLOOKUP(XLOOKUP(x,A2:A6,B2:B6),D2:D6,E2:E6)))

filter()函数。

=@FILTER($E$2:$E$6,$D$2:$D$6=FILTER($B$2:$B$6,$A$2:$A$6=B10))

There are few ways to do that. XLOOKUP() may best fit.

=XLOOKUP(XLOOKUP(B10,$A$2:$A$6,$B$2:$B$6,""),$D$2:$D$6,$E$2:$E$6,"")

If you are on Excel-2016 then can use INDEX/MATCH like-

=INDEX($E$2:$E$6,MATCH(INDEX($B$2:$B$6,MATCH(B10,$A$2:$A$6,0)),$D$2:$D$6,0))

With VLOOKUP() can try-

=VLOOKUP(VLOOKUP(B10,$A$2:$B$6,2,FALSE),$D$2:$E$6,2,FALSE)

With most recent release of Microsoft-365 can use BYROW() for one go.

=BYROW(B10:B14,LAMBDA(x,XLOOKUP(XLOOKUP(x,A2:A6,B2:B6),D2:D6,E2:E6)))

And by FILTER() function.

=@FILTER($E$2:$E$6,$D$2:$D$6=FILTER($B$2:$B$6,$A$2:$A$6=B10))

enter image description here

芯好空 2025-02-19 21:42:35

另一种方法是使用电源查询。也许这就是您想要的6000行,这就是您想要的。

您可以将两个输入表作为Excel表设置,我们称它们为 Tabletype TableProduct

单击表中的任何位置,并保持 ctrl + t 。然后在表设计选项卡中,输入上述名称。

然后您可以进入电源查询编辑器,并使用下面的脚本合并两个表。

data>获取数据>来自其他来源>空白查询

”在此处输入图像描述”

然后将此脚本粘贴到写入高级编辑器的空脚本上。

let
   dimProduct = Excel.CurrentWorkbook(){[Name="tableProduct"]}[Content],
   dimType = Excel.CurrentWorkbook(){[Name="tableType"]}[Content],
   Source = Table.NestedJoin(dimProduct, {"Product"}, dimType, {"Product"}, "dimType", JoinKind.LeftOuter),
   #"Expanded tableType" = Table.ExpandTableColumn(Source, "dimType", {"Type"}, {"Type"}),
   #"Removed Columns" = Table.RemoveColumns(#"Expanded tableType",{"Product"}),
   #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Type", "Vendor"}),
   #"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Type", type text}, {"Vendor", type text}})
in
   #"Changed Type"

然后关闭并加载到并选择要桌子去的地方。要更新它,右键单击刷新

Another approach would be to use Power Query. Perhaps this is what you want if you are working with 6000 rows.

You could set up your two input tables as Excel Tables, let's call them tableType and tableProduct.

Click anywhere in the table and hold CTRL + t. Then in the Table Design tab, enter the names as above.

enter image description here

You can then go into the Power Query editor and use the script below to merge the two tables.

Data > Get Data > From Other Sources > Blank Query

enter image description here

Then paste this script over the empty script that is written into the Advanced Editor.

let
   dimProduct = Excel.CurrentWorkbook(){[Name="tableProduct"]}[Content],
   dimType = Excel.CurrentWorkbook(){[Name="tableType"]}[Content],
   Source = Table.NestedJoin(dimProduct, {"Product"}, dimType, {"Product"}, "dimType", JoinKind.LeftOuter),
   #"Expanded tableType" = Table.ExpandTableColumn(Source, "dimType", {"Type"}, {"Type"}),
   #"Removed Columns" = Table.RemoveColumns(#"Expanded tableType",{"Product"}),
   #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Type", "Vendor"}),
   #"Changed Type" = Table.TransformColumnTypes(#"Reordered Columns",{{"Type", type text}, {"Vendor", type text}})
in
   #"Changed Type"

Then Close and Load To and choose where you want your table to go. To update it, Right-Click and Refresh.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文