从表中查找值

发布于 2025-01-16 21:57:55 字数 369 浏览 1 评论 0原文

我想编写一个公式来获取表 1 中特定订单 ID(第 1 列)的出发城市和到达城市(第 2 列和第 3 列)之间的距离(第 4 列),同时从距离工作表中查找数据,如下所示。

表 1

距离工作表: 距离工作表

Please I want to write a formula to get the Distance (4th column) between From and To Cities (2nd and 3rd columns) for a particular Order ID (1st column) in Table 1 while looking up data from the Distances worksheet as shown below.

Table 1

Distances worksheet:
Distances worksheet

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

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

发布评论

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

评论(3

温柔戏命师 2025-01-23 21:57:55

使用单元格 D2 中使用的 XLOOKUP() 函数

公式 --> 适用于 Excel 2021 和 Excel 2021仅限 O365 用户

=XLOOKUP(B2,$F$3:$F$7,XLOOKUP(C2,$G$2:$K$2,$G$3:$K$7),"Not Found")

FORMULA_SOLUTION

因此,第二个 XLOOKUP() 函数返回

XLOOKUP(C2,$G$2:$K$2,$G$3:$K$7)

返回从以下任一位置获取的距离 (km) B 列中列出的到达堪培拉的地点,因为我以第一个单元格为例,所以它显示的是堪培拉,这就是对于 C 列中的其他 Destination 也是如此,

{285;676;1199;3735;0}

最后将其包装在另一个 XLOOKUP() 函数中,其中查找值来自于 列B 应返回准确的距离 必需的。

3 个替代公式:

• 对于所有用户

=VLOOKUP(B2,$F$3:$K$7,MATCH(C2,$F$2:$K$2,0),0)

• 对于 Office 365 和 Office 365 Excel 2021

=FILTER(FILTER($G$3:$K$7,(B2=$F$3:$F$7)),C2=$G$2:$K$2)

• 适用于 Office 365 和 Office 365 Excel 2021

=INDEX(FILTER($G$3:$K$7,B2=$F$3:$F$7),XMATCH(C2,$G$2:$K$2,0))

注意:为了方便起见,我在同一工作表中显示了两个表,因此您可能需要根据您的数据库相应地更改范围。

Using XLOOKUP() Function

Formula used in cell D2 --> Applicable To Excel 2021 & O365 Users Only

=XLOOKUP(B2,$F$3:$F$7,XLOOKUP(C2,$G$2:$K$2,$G$3:$K$7),"Not Found")

FORMULA_SOLUTION

So, the second XLOOKUP() Function returns

XLOOKUP(C2,$G$2:$K$2,$G$3:$K$7)

Returns the Distance (km) that takes from any of the places listed in Column B to reach Canberra, since I have taken the first cell as an example so its showing for the Canberra, this goes same for the other Destinations in Column C

{285;676;1199;3735;0}

Lastly wrapping this one within another XLOOKUP() Function where the lookup value is from the Column B shall return the exact distance required.

3 Alternative formulas:

• For All Users

=VLOOKUP(B2,$F$3:$K$7,MATCH(C2,$F$2:$K$2,0),0)

• For Office 365 & Excel 2021

=FILTER(FILTER($G$3:$K$7,(B2=$F$3:$F$7)),C2=$G$2:$K$2)

• For Office 365 & Excel 2021

=INDEX(FILTER($G$3:$K$7,B2=$F$3:$F$7),XMATCH(C2,$G$2:$K$2,0))

Note: For convenience I have shown both the tables in same worksheet, hence you may need to change the ranges accordingly as per your database.

云仙小弟 2025-01-23 21:57:55

这是一个快速版本:

INDEX(A2:D5,MATCH(B8,A2:A5,0),MATCH(B9,A2:D2,0))

在此输入图片描述

B8为起点,B9为终点。
没有重复您的所有数据,因为您将其作为图片提供,我懒得输入所有这些数据。

So a quick version:

INDEX(A2:D5,MATCH(B8,A2:A5,0),MATCH(B9,A2:D2,0))

enter image description here

B8 is the starting point, B9 end.
Did not repeat all your data as you gave it as a picture and I am too lazy to type all of that.

两个我 2025-01-23 21:57:55

您可以使用 AVERAGEIFS 轻松完成此操作:

在此处输入图像描述

单元格 H4 中的公式:

=IF(H$3=$G4;"";AVERAGEIFS($D$2:$D$19;$B$2:$B$19;$G4;$C$2:$C$19;H$3))

拖至左侧并拖至底部。

您需要使用 AVERAGEIFS,因为点之间的距离在两个方向上相同。因为在您的数据中,您在 OrderId 2 中获得了 Melbourner - Sidney ,并在 OrderId 4 中获得了 Sidney - Melbourne 。这是相同的重复距离,因此如果您只是求和,你会产生一个错误。

You can do it easily with AVERAGEIFS:

enter image description here

Formula in cell H4:

=IF(H$3=$G4;"";AVERAGEIFS($D$2:$D$19;$B$2:$B$19;$G4;$C$2:$C$19;H$3))

Drag to left and drag to bottom.

You need to use AVERAGEIFS because distance between points is the same in both directions. Because in your data yo got, as example, Melbourner - Sidney in OrderId 2 and got Sidney - Melbourne in OrderId 4. It's the same distance duplicated so if you just sum, you will create an error.

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