Information Technology Topic

VLOOKUP, RANK and DATE

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. VLOOKUP searches the first column of a table for a value and returns the entry from a chosen column of the same row: =VLOOKUP(value, table, column number, match type)
  2. Exact match (FALSE) needs the value to be in the table, otherwise the cell shows #N/A; approximate match needs the first column sorted from smallest to largest and uses the nearest lower value
  3. RANK(value, range, order) gives a value's position in a list (order 0 puts the largest first), and DATE(year, month, day) builds a date from three whole numbers

Section 1Looking a value up in a table

A shop in Portmore has a price list: each product has a code, a name and a price. At the till, the cashier types a code and the sheet should show the price. Copying prices by hand would be slow and full of slips. The VLOOKUP function does the job. It searches down the first column of a table for the value you give it, finds that row, and then returns the entry from the column you choose, in the same row. Here's the trick: the thing you know (the code) must be in the first column of the table. The thing you want (the price) can be in any column to its right.

Section 2The four parts of VLOOKUP

The pattern is =VLOOKUP(value to find, table range, column number, match type). The arguments sit inside one set of brackets, separated by the list separator (a comma in most set-ups). Say the price list is in A2:C5, with the code in column A, the name in B and the price in C. Then =VLOOKUP(102,A2:C5,3,FALSE) reads: find 102 in the first column of A2:C5, then give me the entry from column 3 of that row. The column number counts inside the table, and the first column of the table is number 1. So in A2:C5, column 1 is A, column 2 is B and column 3 is C. If the table were in C2:E5, then 3 would mean column E.

Section 3Exact match: FALSE

Use FALSE as the last argument when the value must be found exactly, as with product codes, ID numbers and names. The table does not have to be sorted. Text you are looking for goes in quotation marks, such as =VLOOKUP("C",G2:H5,2,FALSE) for a bus fare zone. If the value is not in the first column, the cell shows the error #N/A. For example, =VLOOKUP(105,A2:C5,3,FALSE) shows #N/A when the codes only run from 101 to 104. Watch out: #N/A is not a fault in the formula. It is the sheet telling you the value was not found, which is a useful warning that a code has been mistyped.

Section 4Approximate match: sorted bands

Sometimes you want a band, not an exact hit. A post office charges by weight bands: from 0 g it is J$120, from 100 g it is J$180, from 250 g it is J$260, and from 500 g it is J$400. With the weights in the first column, =VLOOKUP(249,E2:F5,2) gives 180, because the sheet takes the nearest lower value in the first column, which is 100. A weight of 250 gives 260 and a weight of 520 gives 400. This works when the last argument is TRUE or is left out. The rule is that the first column must be sorted from smallest to largest, or the answers cannot be trusted. Easy to mix up: leaving the last argument out means approximate, not exact. Typing a wrong product code without FALSE could quietly return the nearest lower code's price.

Section 5RANK: finding a position in a list

RANK tells you where a value stands in a list. The pattern is =RANK(value, range, order). The range is the whole list, and the value is the one you want to place. The order argument is 0 or 1. Order 0 ranks as if the list were sorted from largest to smallest, so the largest value gets rank 1. This is also what happens when you leave the order out. Order 1 ranks as if the list were sorted from smallest to largest, so the smallest value gets rank 1. For marks in B2:B7 of 66, 91, 78, 54, 85 and 70, =RANK(78,B2:B7) gives 3, because only 91 and 85 are larger. For race times, where the smallest time is the best, use order 1: the fastest runner gets rank 1.

Section 6DATE and TODAY

The DATE function builds a date from three whole numbers, in the order year, month, day: =DATE(1962,8,6) stands for 6 August 1962, the year Jamaica became independent. It is the safe way to give a date inside a formula, because the slash means divide there, so 25/12/2026 would be worked out as a division sum and not read as a date. The TODAY function takes no arguments, so its brackets stay empty: =TODAY(). It shows the current date from the computer's clock, and it updates when the sheet recalculates, so tomorrow it shows tomorrow's date. The two do different jobs. DATE gives a date you choose and it never changes. TODAY gives whatever date it is now.

Section 7Choosing and typing the right function

Ask what the job is. To get a price from a code, use VLOOKUP. To find a position in a list, use RANK. To enter a fixed date, use DATE. To show the current date, use TODAY. When you type any of them, check that the formula starts with =, that the brackets match, that the arguments are separated correctly, and that any words are in quotation marks. These are the same rules as for every function. If you copy a lookup or a rank formula down a column, the table range or the list must not slide down with the formula. Lock it with dollar signs, as in =RANK(B2,$B$2:$B$7). The rules for that are in the topic on relative and absolute addressing.

Examples

A shop in Portmore keeps a price list in A2:C5. Column A holds the product code, column B the name and column C the price in J$. 101 Rice 3250, 102 Flour 4500, 103 Oil 2100, 104 Sugar 1800. (a) State what =VLOOKUP(102,A2:C5,2,FALSE) shows. (b) Write a formula that shows the price of code 104 and state the value. (c) State what =VLOOKUP(105,A2:C5,3,FALSE) shows and explain why.

(a) The sheet looks for 102 in column A and finds it in the second row of the table. The column number is 2, so it returns the entry from column B, which is Flour. (b) The price is in column C, which is column 3 of the table, and the code must match exactly, so use =VLOOKUP(104,A2:C5,3,FALSE). Code 104 is Sugar, so the value shown is 1800. (c) It shows #N/A. The last argument FALSE asks for an exact match, and 105 is not in the first column, which only holds 101 to 104. #N/A is the sheet's way of saying the value was not found.

A shop pays sales commission by band. The bands are in G2:H5, sorted from smallest to largest: from 0 the rate is 0%, from 20000 it is 2%, from 40000 it is 5% and from 60000 it is 8%. The sales for four staff are in B2:B5: Kemar 18500, Shanice 45500, Andre 60000 and Tia 38200. Column C holds =VLOOKUP(B2,$G$2:$H$5,2,TRUE) copied down, column D holds =B2*C2, and column E holds =RANK(B2,$B$2:$B$5). (a) Find the rate in C2 to C5. (b) Find the commission in D2 to D5 and the total commission. (c) Find the rank in E2 to E5. (d) Explain why the first column of the band table must be sorted.

(a) Approximate match takes the nearest lower value in the first column. Kemar: 18500 is below 20000, so the nearest lower value is 0 and the rate is 0%. Shanice: 45500 lies between 40000 and 60000, so the rate is 5%. Andre: 60000 is exactly a band start, so the rate is 8%. Tia: 38200 lies between 20000 and 40000, so the rate is 2%. (b) Multiply sales by rate. Kemar: 18500 × 0 = 0. Shanice: 45500 × 0.05 = 2275. Andre: 60000 × 0.08 = 4800. Tia: 38200 × 0.02 = 764. Total commission: 0 + 2275 + 4800 + 764 = 7839. (c) The default order ranks from largest to smallest. Andre has the largest sales, so rank 1. Shanice is second with rank 2, Tia is third with rank 3, and Kemar is fourth with rank 4. (d) An approximate match relies on the values being in order from smallest to largest, so that the nearest lower value can be found. If the table were jumbled, the sheet could return the wrong band. The dollar signs lock the table so it does not slide down when the formula is copied.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from