Data Analytics Lab 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Data Analytics Lab Part- A: Spreadsheet (Excel) Lab3

VLOOKUP, HLOOKUP, XLOOKUP, COUNT, COUNTA

VLOOKUP, HLOOKUP, XLOOKUP, COUNT, and COUNTA are functions in Microsoft Excel that help
users perform various tasks related to data lookup and counting.

Contents
1.VLOOKUP (Vertical Lookup):...............................................................................................................1
2.HLOOKUP (Horizontal Lookup):..........................................................................................................2
3. XLOOKUP:..........................................................................................................................................3
4. COUNT:..............................................................................................................................................4
5. COUNTA:............................................................................................................................................5

1.VLOOKUP (Vertical Lookup):


This function is used to search for a value in the first column of a table array and return a
value from the same row in a specified column. The syntax for VLOOKUP is:

VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])

- `lookup_value`: The value you want to look for in the first column of the table.

- `table_array`: The table range in which you want to search for the lookup value.

- `col_index_num`: The column number of the value you want to return (from the same row).

- `[range_lookup]`: An optional parameter, TRUE (approximate match) or FALSE (exact match).

Certainly! Let's use an example to explain how VLOOKUP works.

Suppose you have a table with product IDs, product names, and prices as follows:

You want to find the price of the product with ID 1002. You can use the VLOOKUP function as
follows:
Let's break down the VLOOKUP function:

- `lookup_value`: The value you want to look for in the first column of the table, in this case, 1002.

- `table_array`: The table range in which you want to search for the lookup value, which is A1:C4 in
this example.

- `col_index_num`: The column number of the value you want to return (from the same row), which
is 3 in this case, as we want to return the value from the "Price" column.

- `[range_lookup]`: An optional parameter, TRUE (approximate match) or FALSE (exact match). In this
example, we use FALSE for an exact match.

The function will search for the value 1002 in the first column of the table (column A). It will find this
value in row 3. Then, it will return the value from the same row in the specified column (column 3),
which is $0.50. So the result of the VLOOKUP function in this example will be $0.50, which is the
price of the product with ID 1002.

2.HLOOKUP (Horizontal Lookup):


Similar to VLOOKUP, this function searches for a value in the first row of a table array and returns a
value from the same column in a specified row. The syntax for HLOOKUP is:

HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])

Sure! Let's use a more detailed example to explain how HLOOKUP works.

Suppose you have a table with months in the first row and sales amounts for each month in different
regions (North, South, East, and West) as follows:

You want to find the sales amount for the month of March in the East region. You can use the
HLOOKUP function as follows:

Let's break down the HLOOKUP function:

- `lookup_value`: The value you want to look for in the first row of the table, in this case, "March".

- `table_array`: The table range in which you want to search for the lookup value, which is B1:E5 in
this example.
- `row_index_num`: The row number of the value you want to return (from the same column), which
is 4 in this case, as we want to return the value from the "East" region row.

- `[range_lookup]`: An optional parameter, TRUE (approximate match) or FALSE (exact match). In this
example, we use FALSE for an exact match.

The function will search for the value "March" in the first row of the table (row 1). It will find this
value in column D. Then, it will return the value from the same column in the specified row (row 4),
which is $5,000. So the result of the HLOOKUP function in this example will be $5,000, which is the
sales amount for the month of March in the East region.

3. XLOOKUP:
This is a more versatile function that replaces VLOOKUP and HLOOKUP, allowing you to search for a
value in any column or row. The syntax for XLOOKUP is:

XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode],


[search_mode])

Sure! Let's use a detailed example to explain how XLOOKUP works.

Suppose you have a table with product names in column A, product IDs in column B, and prices in
column C as follows:

You want to find the price of the product with ID 1002. You can use the XLOOKUP function as
follows:

Let's break down the XLOOKUP function:

- `lookup_value`: The value you want to look for, in this case, 1002.

- `lookup_array`: The range in which you want to search for the lookup value, which is B2:B4 in this
example.

- `return_array`: The range from which you want to return the value corresponding to the found
lookup value, which is C2:C4 in this case, as we want to return the value from the "Price" column.

The function will search for the value 1002 in the lookup_array (column B). It will find this value in
row 3. Then, it will return the value from the same row in the return_array (column C), which is
$0.50. So the result of the XLOOKUP function in this example will be $0.50, which is the price of the
product with ID 1002.

You can also use XLOOKUP to find the product name for the product with ID 1002 as follows:

This will return "Orange", which is the product name for the product with ID 1002.

4. COUNT:
This function counts the number of cells containing numerical values in a specified range. The syntax
for COUNT is:

COUNT(value1, [value2], ...)

Here are two more examples of using the COUNT function:

Example 1: Count cells with numbers across multiple columns

Suppose you have a table with test scores for different subjects as follows:

You want to count how many cells have numerical scores in each row. You can use the COUNT
function as follows:

Row 2: `=COUNT(A2:C2)` - This will return 3, as there are three cells with numbers in row 2.

Row 3: `=COUNT(A3:C3)` - This will return 2, as there are two cells with numbers in row 3.

Row 4: `=COUNT(A4:C4)` - This will return 3, as there are three cells with numbers in row 4.

Row 5: `=COUNT(A5:C5)` - This will return 2, as there are two cells with numbers in row 5.

Example 2: Count cells with numbers in multiple non-adjacent columns

Suppose you have the same table as before, but now you only want to count cells with numbers in
columns A and C:
You can use the COUNT function as follows:

`=COUNT(A2:A5, C2:C5)`

This will return 7, as there are seven cells with numbers in columns A and C (rows 2 to 5).

5. COUNTA:
This function counts the number of non-empty cells in a specified range, including cells containing
text, numbers, or other types of data. The syntax for COUNTA is:

COUNTA(value1, [value2], ...)

These functions can be very helpful in organizing, analyzing, and managing data in Excel
spreadsheets.

Example 1: Count non-empty cells across multiple columns

Suppose you have a table with names, ages, and cities as follows:

You want to count how many non-empty cells are in each row. You can use the COUNTA function as
follows:

Row 2: `=COUNTA(A2:C2)` - This will return 3, as there are three non-empty cells in row 2.

Row 3: `=COUNTA(A3:C3)` - This will return 2, as there are two non-empty cells in row 3.

Row 4: `=COUNTA(A4:C4)` - This will return 2, as there are two non-empty cells in row 4.

Row 5: `=COUNTA(A5:C5)` - This will return 2, as there are two non-empty cells in row 5.

Example 2: Count non-empty cells in multiple non-adjacent columns


Suppose you have the same table as before, but now you only want to count non-empty cells in
columns A and C:

You can use the COUNTA function as follows:

`=COUNTA(A2:A5, C2:C5)`

This will return 4, as there are four non-empty cells in columns A and C (rows 2 to 5).

You might also like