您的位置:首页 > 其它

Excel数据分析与业务建模_第二章_查找函数VLOOKUP及HLOOKUP(语法及应用实例)

2017-01-15 23:50 796 查看
说句实在的,如果不使用查找函数的话,现在手头上的工作基本上都没法完成。
在数据量动辄几十万行的多个数据表间整理数据,基本上就靠VLOOKUP函数了。

1. LOOKUP函数的语法构成:
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup]),共4个参数。lookup_value类似于SQL查询时的查询条件或主键,table_array是以lookup_value为第一列的数据区(表),col_index_num是查询目标在数据区的列号(如在第二列,则为2),range_lookup是个可选参数(TRUE或FALSE),但是很有讲究。为TRUE时,为模糊查询;为FALSE时,为精确查询。目前工作中只用精确查询(生产数据,容不得半点“模糊”)。但不要以为TRUE就没用了,在超额累进税率、大额购买优惠时的总额计算(如,第二杯半价)等很多问题的解决过程中,都是用TRUE来完成的。

2. 新发现:
a. TRUE是很有用的
b. HLOOKUP有时也是很自然的用法(用VLOOKUP替代也行,但需要行列转换)

Lookup functions enable you to look up values from worksheet ranges. In Microsoft Excel 2013, you can perform both vertical lookups (by using the VLOOKUP function) and horizontal lookups (by using the HLOOKUP function). In a vertical lookup, the lookup operation
starts in the first column of a worksheet range. In a horizontal lookup, the operation starts in the first row of a worksheet range.

Because the majority of formulas using lookup functions involve vertical lookups, this chapter concentrates on VLOOKUP functions. VLOOKUp syntax

The syntax of the VLOOKUP function is as follows. The brackets ([ ]) indicate optional arguments. VLOOKUP(lookup value, table range,column index,[range lookup])

■ Lookup value is the value you want to look up in the first column of the table range.

■ Table range is the range that contains the entire lookup table. The table range includes the first column, in which you try to match the lookup value, and any other columns in which you want to look up formula results.

■ Column index is the column number in the table range from which the value of the lookup function is obtained.

■ Range lookup is an optional argument. The point of range lookup is to specify an exact or approximate match. If the range lookup argument is True or omitted, the first column of the table range must be in ascending numerical order. If the range lookup argument
is True or omitted and an exact match to the lookup value is found in the first column of the table

3. 应用实例:
a. 个人所得税计算



将范围部分编码为“超过金额”列(lookup value),数据区共3列(超过金额、税率及速算扣除数)。
然后,任意输入社保、公积金等可在个人所得税税前扣除的金额,即可自动计算税后收入。



公式:
适用税率=VLOOKUP(税前工资,税率表,2),
适用速算扣除数=VLOOKUP(税前工资,税率表,3)

话说这张表也是七年前创建的,睹物思人,感慨万千。。。

b. 大额购买优惠的计算

这个问题看似不难,但耗了我两三个小时,只因我一心想重用(reuse)一下税率查询时的方法。最后没办法,看了下答案。
有时,一个问题上耗得时间太长,很有可能需要转换一下思路了。

问题:
You are thinking of advertising Microsoft products on a popular TV music program. You pay one price for the first group of ads, but as you buy more ads, the price per ad decreases as shown in the following table:



For example, if you buy 8 ads, you pay $12,000 per ad for the first 5 ads and $11,000 for each of the next 3 ads. If you buy 14 ads, you pay $12,000 for each of the first 5 ads, $11,000 for each of the next 5 ads, and $10,000 for each of the last 4 ads.
Write a formula that yields the total cost of purchasing any number of ads. Hint: You probably need at least three columns in your table range, and your formula might involve two lookup functions.

解答:



我的失误就在于偷懒没设置“节点金额(cost up to breakpoint)”这一列。

总金额=节点金额+(购买数量-节点数量+1)*单价,如购买数量为7时,根据购买数量查询数据表得知,单价为11000,节点金额为60000,由此计算出总金额=60000+(7-6+1)*11000=82000。(验证:前5件共12000*5=60000,超出5件后的两件单价按11000计算,计22000,共计82000)

其中,Total=VLOOKUP(C27,price_2,3)+(C27+1-VLOOKUP(C27,price_2,1))*VLOOKUP(C27,price_2,2)

c. 横向查找的使用
以后有机会,准备用一用:)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: