Excel中的VLOOKUP,第2部分:在没有数据库的情况下使用VLOOKUP-程序员宅基地

技术标签: python  java  机器学习  人工智能  数据库  

In a recent article, we introduced the Excel function called VLOOKUP and explained how it could be used to retrieve information from a database into a cell in a local worksheet.  In that article we mentioned that there were two uses for VLOOKUP, and only one of them dealt with querying databases.  In this article, the second and final in the VLOOKUP series, we examine this other, lesser known use for the VLOOKUP function.

在最近的文章中,我们介绍了称为VLOOKUP的Excel函数,并解释了如何使用该函数将数据库中的信息检索到本地工作表中的单元格中。 在那篇文章中,我们提到了VLOOKUP有两种用法,其中只有一种用于查询数据库。 在本文(VLOOKUP系列的第二篇也是最后一篇)中,我们研究了VLOOKUP函数的另一种鲜为人知的用法。

If you haven’t already done so, please read the first VLOOKUP article – this article will assume that many of the concepts explained in that article are already known to the reader.

如果您尚未这样做,请阅读第一篇VLOOKUP文章 -本文将假定读者已经知道该文章中解释的许多概念。

When working with databases, VLOOKUP is passed a “unique identifier” that serves to identify which data record we wish to find in the database (e.g. a product code or customer ID).  This unique identifier must exist in the database, otherwise VLOOKUP returns us an error.  In this article, we will examine a way of using VLOOKUP where the identifier doesn’t need to exist in the database at all.  It’s almost as if VLOOKUP can adopt a “near enough is good enough” approach to returning the data we’re looking for.  In certain circumstances, this is exactly what we need.

使用数据库时,VLOOKUP传递了一个“唯一标识符”,该标识符用于标识我们希望在数据库中找到的数据记录(例如产品代码或客户ID)。 该唯一标识符必须存在于数据库中,否则VLOOKUP向我们返回错误。 在本文中,我们将研究一种使用VLOOKUP的方法,其中标识符根本不需要在数据库中存在。 VLOOKUP几乎可以采用“足够近就足够好”的方法来返回我们正在寻找的数据。 在某些情况下,这正是我们所需要的。

We will illustrate this article with a real-world example – that of calculating the commissions that are generated on a set of sales figures.  We will start with a very simple scenario, and then progressively make it more complex, until the only rational solution to the problem is to use VLOOKUP.  The initial scenario in our fictitious company works like this:  If a salesperson creates more than $30,000 worth of sales in a given year, the commission they earn on those sales is 30%.  Otherwise their commission is only 20%.  So far this is a pretty simple worksheet:

我们将以一个真实的例子来说明这篇文章-计算一组销售数据所产生的佣金。 我们将从一个非常简单的场景开始,然后逐步使其变得更加复杂,直到对该问题唯一的合理解决方案是使用VLOOKUP。 我们在虚拟公司中的初始方案是这样的:如果销售人员在给定年份创造了价值30,000美元以上的销售,则他们从这些销售中获得的佣金为30%。 否则,他们的佣金仅为20%。 到目前为止,这是一个非常简单的工作表:

original

To use this worksheet, the salesperson enters their sales figures in cell B1, and the formula in cell B2 calculates the correct commission rate they are entitled to receive, which is used in cell B3 to calculate the total commission that the salesperson is owed (which is a simple multiplication of B1 and B2).

要使用此工作表,销售人员在单元格B1中输入他们的销售数字,单元格B2中的公式将计算出他们有权获得的正确佣金率,并在单元格B3中使用该佣金率来计算应支付给销售人员的总佣金(是B1和B2的简单乘法)。

The cell B2 contains the only interesting part of this worksheet – the formula for deciding which commission rate to use: the one below the threshold of $30,000, or the one above the threshold.  This formula makes use of the Excel function called IF.  For those readers that are not familiar with IF, it works like this:

单元格B2包含此工作表中唯一有趣的部分–确定使用哪种佣金率的公式: 低于 $ 30,000阈值的阈值或高于 $ 30,000阈值的阈值。 该公式利用了称为IF的Excel函数。 对于那些不熟悉IF的读者,它的工作方式如下:

IF(condition,value if true,value if false)

IF( 条件,如果为true,则为false )

Where the condition is an expression that evaluates to either true or false.  In the example above, the condition is the expression B1<B5, which can be read as “Is B1 less than B5?”, or, put another way, “Are the total sales less than the threshold”.  If the answer to this question is “yes” (true), then we use the value if true parameter of the function, namely B6 in this case – the commission rate if the sales total was below the threshold.  If the answer to the question is “no” (false), then we use the value if false parameter of the function, namely B7 in this case – the commission rate if the sales total was above the threshold.

条件是表达式,其结果为truefalse 。 在上面的示例中, 条件是表达式B1 <B5 ,可以理解为“ B1是否小于B5?”,或者换句话说,“总销售额是否小于阈值”。 如果对这个问题的回答是“是”(true),则我们使用该函数的参数if true ,在这种情况下为B6 –如果销售总额低于阈值,则为佣金率。 如果问题的答案为“否”(否),那么我们使用该函数的false参数值(在这种情况下为B7) –如果销售总额高于阈值,则为佣金率。

As you can see, using a sales total of $20,000 gives us a commission rate of 20% in cell B2.  If we enter a value of $40,000, we get a different commission rate:

如您所见,使用总计20,000美元的销售额,我们在单元格B2中的佣金率为20%。 如果我们输入的值为$ 40,000,我们将获得不同的佣金率:

original40k

So our spreadsheet is working.

因此,我们的电子表格正在运行。

Let’s make it more complex.  Let’s introduce a second threshold:  If the salesperson earns more than $40,000, then their commission rate increases to 40%:

让我们使其更复杂。 让我们介绍第二个阈值:如果销售人员的收入超过40,000美元,那么他们的佣金率将提高到40%:

2thresholds

Easy enough to understand in the real world, but in cell B2 our formula is getting more complex.  If you look closely at the formula, you’ll see that the third parameter of the original IF function (the value if false) is now an entire IF function in its own right.  This is called a nested function (a function within a function).  It’s perfectly valid in Excel (it even works!), but it’s harder to read and understand.

在现实世界中很容易理解,但是在单元格B2中,我们的公式变得越来越复杂。 如果仔细看一下公式,您会发现原始IF函数的第三个参数( 如果为false )现在本身就是整个IF函数。 这称为嵌套函数 (函数中的函数)。 它在Excel中是完全有效的(甚至可以使用!),但是很难阅读和理解。

We’re not going to go into the nuts and bolts of how and why this works, nor will we examine the nuances of nested functions.  This is a tutorial on VLOOKUP, not on Excel in general.

我们不会深入探讨其工作方式和原因,也不会研究嵌套函数的细微差别。 这是有关VLOOKUP的教程,通常不是有关Excel的教程。

Anyway, it gets worse!  What about when we decide that if they earn more than $50,000 then they’re entitled to 50% commission, and if they earn more than $60,000 then they’re entitled to 60% commission?

无论如何,情况变得更糟! 当我们决定如果他们的收入超过50,000美元,那么他们有权获得50%的佣金;如果他们的收入超过60,000美元,那么他们有权获得60%的佣金,那该怎么办?

4thresholds

Now the formula in cell B2, while correct, has become virtually unreadable.  No-one should have to write formulae where the functions are nested four levels deep!  Surely there must be a simpler way?

现在,单元格B2中的公式虽然正确,但实际上已变得不可读。 没有人应该写公式来将函数嵌套四个层次! 当然必须有一种更简单的方法吗?

There certainly is.  VLOOKUP to the rescue!

当然有。 VLOOKUP进行救援!

Let’s redesign the worksheet a bit.  We’ll keep all the same figures, but organize it in a new way, a more tabular way:

让我们重新设计工作表。 我们将保留所有相同的数字,但以一种新的方式,以一种更表格的方式来组织它:

tableblank

Take a moment and verify for yourself that the new Rate Table works exactly the same as the series of thresholds above.

请花点时间为自己核实新的费率表与上述一系列阈值完全相同。

Conceptually, what we’re about to do is use VLOOKUP to look up the salesperson’s sales total (from B1) in the rate table and return to us the corresponding commission rate.  Note that the salesperson may have indeed created sales that are not one of the five values in the rate table ($0, $30,000, $40,000, $50,000 or $60,000).  They may have created sales of $34,988.  It’s important to note that $34,988 does not appear in the rate table.  Let’s see if VLOOKUP can solve our problem anyway…

从概念上讲,我们要做的是使用VLOOKUP在费率表中查找销售员的销售总额(来自B1),并向我们返回相应的佣金率。 请注意,销售人员可能确实创建了不是费率表中的五个值之一的销售($ 0,$ 30,000,$ 40,000,$ 50,000或$ 60,000)。 他们可能创造了$ 34,988的销售额。 请注意,费率表中显示$ 34,988。 让我们看看VLOOKUP是否可以解决我们的问题……

We select cell B2 (the location we want to put our formula), and then insert the VLOOKUP function from the Formulas tab:

我们选择单元格B2(要放置公式的位置),然后从“ 公式”选项卡中插入VLOOKUP函数:

findfunc

The Function Arguments box for VLOOKUP appears.  We fill in the arguments (parameters) one by one, starting with the Lookup_value, which is, in this case, the sales total from cell B1.  We place the cursor in the Lookup_value field and then click once on cell B1:

出现VLOOKUP的功能参数框。 我们从Lookup_value开始一个接一个地填充参数(参数),在这种情况下,它是来自单元格B1的销售总额。 我们将光标放在Lookup_value字段中,然后在单元格B1上单击一次:

args1

Next we need to specify to VLOOKUP what table to lookup this data in.  In this example, it’s the rate table, of course.  We place the cursor in the Table_array field, and then highlight the entire rate table – excluding the headings:

接下来,我们需要向VLOOKUP指定在哪个表中查找此数据。当然,在此示例中,这是费率表。 我们将光标放在Table_array字段中,然后突出显示整个汇率表- 不包括标题

args2

Next we must specify which column in the table contains the information we want our formula to return to us.  In this case we want the commission rate, which is found in the second column in the table, so we therefore enter a 2 into the Col_index_num field:

接下来,我们必须指定表中的哪一列包含我们希望公式返回给我们的信息。 在这种情况下,我们需要在表的第二列中找到的佣金率,因此,我们在Col_index_num字段中输入2

args3

Finally we enter a value in the Range_lookup field.

最后,我们在Range_lookup字段中输入一个值。

Important:  It is the use of this field that differentiates the two ways of using VLOOKUP.  To use VLOOKUP with a database, this final parameter, Range_lookup, must always be set to FALSE, but with this other use of VLOOKUP, we must either leave it blank or enter a value of TRUE.  When using VLOOKUP, it is vital that you make the correct choice for this final parameter.

要点:使用此字段可以区分使用VLOOKUP的两种方式。 要将VLOOKUP与数据库一起使用,必须始终将此最终参数Range_lookup设置为FALSE ,但在其他使用VLOOKUP的情况下,我们必须将其保留为空白或输入TRUE 使用VLOOKUP时,至关重要的是您要为该最终参数做出正确的选择。

To be explicit, we will enter a value of true in the Range_lookup field.  It would also be fine to leave it blank, as this is the default value:

明确地说,我们将在Range_lookup字段中输入true值。 也可以将其保留为空白,因为这是默认值:

args4

We have completed all the parameters.  We now click the OK button, and Excel builds our VLOOKUP formula for us:

我们已经完成了所有参数。 现在,我们单击“ 确定”按钮,Excel将为我们建立VLOOKUP公式:

vlookupdone

If we experiment with a few different sales total amounts, we can satisfy ourselves that the formula is working.

如果我们尝试一些不同的销售总额,我们可以使自己满意该公式在起作用。

Conclusion

结论

In the “database” version of VLOOKUP, where the Range_lookup parameter is FALSE, the value passed in the first parameter (Lookup_value) must be present in the database.  In other words, we’re looking for an exact match.

在VLOOKUP的“数据库”版本中, Range_lookup参数为FALSE ,第一个参数( Lookup_value )中传递的值必须存在于数据库中。 换句话说,我们正在寻找完全匹配的内容。

But in this other use of VLOOKUP, we are not necessarily looking for an exact match.  In this case, “near enough is good enough”.  But what do we mean by “near enough”?  Let’s use an example:  When searching for a commission rate on a sales total of $34,988, our VLOOKUP formula will return us a value of 30%, which is the correct answer.  Why did it choose the row in the table containing 30% ?  What, in fact, does “near enough” mean in this case?  Let’s be precise:

但是,在VLOOKUP的这种其他用法中,我们不一定要寻找完全匹配的内容。 在这种情况下,“足够近就足够好”。 但是,“足够接近”是什么意思? 让我们举一个例子:当搜索销售总额为34,988美元的佣金率时,我们的VLOOKUP公式将为我们返回30%的值,这是正确的答案。 为什么选择表中包含30%的行? 实际上,在这种情况下,“足够接近”意味着什么? 确切地说:

When Range_lookup is set to TRUE (or omitted), VLOOKUP will look in column 1 and match the highest value that is not greater than the Lookup_value parameter.

Range_lookup设置为TRUE (或省略)时,VLOOKUP将在列1中查找并匹配不大于 Lookup_value参数的最大值

It’s also important to note that for this system to work, the table must be sorted in ascending order on column 1!

同样重要的是要注意,要使该系统正常工作, 必须在第1列上按升序对表进行排序

If you would like to practice with VLOOKUP, the sample file illustrated in this article can be downloaded from here.

如果您想练习VLOOKUP,可以从此处下载本文中说明的示例文件。

翻译自: https://www.howtogeek.com/howto/14455/vlookup-in-excel-part-2-using-vlookup-without-a-database/

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/culinxia2707/article/details/108788321

智能推荐

稀疏编码的数学基础与理论分析-程序员宅基地

文章浏览阅读290次,点赞8次,收藏10次。1.背景介绍稀疏编码是一种用于处理稀疏数据的编码技术,其主要应用于信息传输、存储和处理等领域。稀疏数据是指数据中大部分元素为零或近似于零的数据,例如文本、图像、音频、视频等。稀疏编码的核心思想是将稀疏数据表示为非零元素和它们对应的位置信息,从而减少存储空间和计算复杂度。稀疏编码的研究起源于1990年代,随着大数据时代的到来,稀疏编码技术的应用范围和影响力不断扩大。目前,稀疏编码已经成为计算...

EasyGBS国标流媒体服务器GB28181国标方案安装使用文档-程序员宅基地

文章浏览阅读217次。EasyGBS - GB28181 国标方案安装使用文档下载安装包下载,正式使用需商业授权, 功能一致在线演示在线API架构图EasySIPCMSSIP 中心信令服务, 单节点, 自带一个 Redis Server, 随 EasySIPCMS 自启动, 不需要手动运行EasySIPSMSSIP 流媒体服务, 根..._easygbs-windows-2.6.0-23042316使用文档

【Web】记录巅峰极客2023 BabyURL题目复现——Jackson原生链_原生jackson 反序列化链子-程序员宅基地

文章浏览阅读1.2k次,点赞27次,收藏7次。2023巅峰极客 BabyURL之前AliyunCTF Bypassit I这题考查了这样一条链子:其实就是Jackson的原生反序列化利用今天复现的这题也是大同小异,一起来整一下。_原生jackson 反序列化链子

一文搞懂SpringCloud,详解干货,做好笔记_spring cloud-程序员宅基地

文章浏览阅读734次,点赞9次,收藏7次。微服务架构简单的说就是将单体应用进一步拆分,拆分成更小的服务,每个服务都是一个可以独立运行的项目。这么多小服务,如何管理他们?(服务治理 注册中心[服务注册 发现 剔除])这么多小服务,他们之间如何通讯?这么多小服务,客户端怎么访问他们?(网关)这么多小服务,一旦出现问题了,应该如何自处理?(容错)这么多小服务,一旦出现问题了,应该如何排错?(链路追踪)对于上面的问题,是任何一个微服务设计者都不能绕过去的,因此大部分的微服务产品都针对每一个问题提供了相应的组件来解决它们。_spring cloud

Js实现图片点击切换与轮播-程序员宅基地

文章浏览阅读5.9k次,点赞6次,收藏20次。Js实现图片点击切换与轮播图片点击切换<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script type="text/ja..._点击图片进行轮播图切换

tensorflow-gpu版本安装教程(过程详细)_tensorflow gpu版本安装-程序员宅基地

文章浏览阅读10w+次,点赞245次,收藏1.5k次。在开始安装前,如果你的电脑装过tensorflow,请先把他们卸载干净,包括依赖的包(tensorflow-estimator、tensorboard、tensorflow、keras-applications、keras-preprocessing),不然后续安装了tensorflow-gpu可能会出现找不到cuda的问题。cuda、cudnn。..._tensorflow gpu版本安装

随便推点

物联网时代 权限滥用漏洞的攻击及防御-程序员宅基地

文章浏览阅读243次。0x00 简介权限滥用漏洞一般归类于逻辑问题,是指服务端功能开放过多或权限限制不严格,导致攻击者可以通过直接或间接调用的方式达到攻击效果。随着物联网时代的到来,这种漏洞已经屡见不鲜,各种漏洞组合利用也是千奇百怪、五花八门,这里总结漏洞是为了更好地应对和预防,如有不妥之处还请业内人士多多指教。0x01 背景2014年4月,在比特币飞涨的时代某网站曾经..._使用物联网漏洞的使用者

Visual Odometry and Depth Calculation--Epipolar Geometry--Direct Method--PnP_normalized plane coordinates-程序员宅基地

文章浏览阅读786次。A. Epipolar geometry and triangulationThe epipolar geometry mainly adopts the feature point method, such as SIFT, SURF and ORB, etc. to obtain the feature points corresponding to two frames of images. As shown in Figure 1, let the first image be ​ and th_normalized plane coordinates

开放信息抽取(OIE)系统(三)-- 第二代开放信息抽取系统(人工规则, rule-based, 先抽取关系)_语义角色增强的关系抽取-程序员宅基地

文章浏览阅读708次,点赞2次,收藏3次。开放信息抽取(OIE)系统(三)-- 第二代开放信息抽取系统(人工规则, rule-based, 先关系再实体)一.第二代开放信息抽取系统背景​ 第一代开放信息抽取系统(Open Information Extraction, OIE, learning-based, 自学习, 先抽取实体)通常抽取大量冗余信息,为了消除这些冗余信息,诞生了第二代开放信息抽取系统。二.第二代开放信息抽取系统历史第二代开放信息抽取系统着眼于解决第一代系统的三大问题: 大量非信息性提取(即省略关键信息的提取)、_语义角色增强的关系抽取

10个顶尖响应式HTML5网页_html欢迎页面-程序员宅基地

文章浏览阅读1.1w次,点赞6次,收藏51次。快速完成网页设计,10个顶尖响应式HTML5网页模板助你一臂之力为了寻找一个优质的网页模板,网页设计师和开发者往往可能会花上大半天的时间。不过幸运的是,现在的网页设计师和开发人员已经开始共享HTML5,Bootstrap和CSS3中的免费网页模板资源。鉴于网站模板的灵活性和强大的功能,现在广大设计师和开发者对html5网站的实际需求日益增长。为了造福大众,Mockplus的小伙伴整理了2018年最..._html欢迎页面

计算机二级 考试科目,2018全国计算机等级考试调整,一、二级都增加了考试科目...-程序员宅基地

文章浏览阅读282次。原标题:2018全国计算机等级考试调整,一、二级都增加了考试科目全国计算机等级考试将于9月15-17日举行。在备考的最后冲刺阶段,小编为大家整理了今年新公布的全国计算机等级考试调整方案,希望对备考的小伙伴有所帮助,快随小编往下看吧!从2018年3月开始,全国计算机等级考试实施2018版考试大纲,并按新体系开考各个考试级别。具体调整内容如下:一、考试级别及科目1.一级新增“网络安全素质教育”科目(代..._计算机二级增报科目什么意思

conan简单使用_apt install conan-程序员宅基地

文章浏览阅读240次。conan简单使用。_apt install conan