Lab 4
Lab 4
LAB # 4
To demonstrate ability to present data concisely in Microsoft Excel
Objectives
In this lab, you will learn how clean and manipulate data in Excel
Use slicers and pivot tables to concisely present data.
Lab Exercise
Task 1:
Open a blank Excel file to practice some important functions related to date and time in Excel. Note that a lot of
data contains data time information. Such data is shared not only in Excel but also among databases, where
format and manipulation of date time plays important role.
The NETWORKDAYS function in Excel is a dominant tool that is designed to calculate the total number of
working days between two identified dates, taking into account weekends and optionally specified holidays.
This function is mainly appreciated for multiple purposes like for project planning, resource allocation, and
deadline tracing.
Let suppose, we have a project deadline within the date of January 1, 2024, and an end date of January 10,
2024. To calculate the total number of working days within this retro, enter the following formula in a cell:
=NETWORKDAYS("2024-01-01", "2024-01-10")
The Microsoft Excel WEEKNUM function returns the week number from a date value.
=WEEKNUM("2024-01-10")
The shortcut CTRL+; enters current time a cell and shortcut CTRL+SHIFT+; enters current date in a cell.
Calculate the difference between 6th February 2022 and 9th September 2024 dates using the DATE function.
The DATE function returns date in Excel date-time format. The date-time format is important as the correct
format ensures that the data is able to be used across several tools outside Excel.
Task 2:
Open the CSC101_Lab_Handout_4_User_Data.xlsx file provided to you. This Excel file contains data for a
number of users related to contact details. We will use this file to practice some important Excel functions.
1. The Excel provided file contains first and last name separately. You can combine the two names in a
new column by using the CONCAT function. Create a new column next to ‘First Name’ column, and
name this column Full Name. In the first cell of new column, write:
Page 1 of 16
Lab Experiment | 4
=CONCAT(B2, A2)
Where B2 is first name and A2 is second name. You can insert space between two names by using
=CONCAT(B2,” “, A2).
The FIND function in Excel is used to return the position of a specific character or substring within a
text string.
2. You are tasked to replace all email addresses with a new email domain name ‘@newmail.com’. Since
an email ID can belong to different domain names and their lengths vary, we will use FIND function to
find position of @ in the email address. The function below will return the position of @ in cell D2.
=FIND("@", D2)
3. You can now use the LEFT function to return the characters of a string from the left till the specified
point. For example, using LEFT(A2,5) will return the first 5 characters of string in cell A2. Using LEFT
and FIND in combination will allow us to extract email addresses till the @ symbol. Make a new
temporary column next to Email Address column and write the function written below:
=LEFT(D2,FIND("@", D2))
Since you want to add newmail.com at the end of this new substring, use CONCAT function used
earlier to add this email domain name at the end of results obtained in temporary column.
One aspect of Excel files with large amounts of data is to clean the data before using it. Often there are
multiple spaces in between text. These can be removed by using TRIM function. Create a temporary
column and remove any extra spaces found in the Street Address column.
4. Excel allows us to use logical operators such as AND, OR, NOT, IF etc. We will demonstrate their
usage in our Excel file. We will ensure that the data provided in the Excel sheet contains email
addresses in proper format in Email Address column and zip codes are also in right format. Check if
email addresses contain @ symbol and Zip column contains number only.
Create a temporary column to check zip codes. use the following function to check format of zip codes.
=ISNUMBER(G2)
Where G2 contains zip number. Note that the output of this result is logical.
In a temporarily created column, use the following function to check format of email address format:
=ISNUMBER(FIND("@",C2))
Where C2 contains an email address. Drag down this formula in cells below to check status of all email
addresses.
To confirm that the row contains all correct entries, use the following function in cell of a new column.
Where H2 and I2 are temporary cells containing results of previous 2 functions. The resultant picture is
shown below for reference:
Page 2 of 16
Lab Experiment | 4
5. Suppose you wish to find rows containing the name John, as winner of lucky draw. You can use nested
IF functions as given below:
=IF(A2="John","Winner",IF(B2="John","Winner","Loser"))
Where A2 and B2 contain names. Drag the formula in cells below to find out results for all rows.
6. Often a function produces errors. The IFERROR function plays an important role in producing outputs
that are error free. Consider the function we used earlier to find @ symbol in email address FIND("@",
D2). Suppose you instead want to find the symbol ? in email address, and you write:
=FIND("?", D2)
Note that it will produce an error, an email address does not contain any ? symbol. To make sure that
Excel function does not create any error in case it does not produce desired result, we will use
IFERROR function with it, as given below:
=IFERROR(FIND("?",C2),"not found")
7. Instead of using text based messages to show right or wrong, true or false results from a column, you
can also use icons to reflect the result based on your rules. First, select the Zip column. Under
‘Conditional Formatting’ option, go to Icon Sets and choose more rules.
Page 3 of 16
Lab Experiment | 4
Now, we wish to apply a rule such that areas with zip code more than 50000 get green signal and those
below 50000 get red signal. Choose the settings as shown below to make these changes.
Page 4 of 16
Lab Experiment | 4
If you check the ‘Show Icon Only’ checkbox, it will replace the text in the column as shown below:
8. You now have reasonable seized data in our worksheet. In real world scenarios, you can have data that
contains hundreds of rows or columns. To move to the start and end of your data, you should be able to
use following shortcuts:
Click on any cell containing data. Press CTRL+RIGHT, the control will move to cell in the right most
column of data.
Press CTRL+LEFT, the control will move to cell in the left most column of data.
Press CTRL+DOWN, the control will move to cell in the last row of data.
Press CTRL+DOWN, the control will move to cell in the last row of data.
Press CTRL+UP, the control will move to cell in the first row of data.
Click on the any cell with data, press CTRL+A, all the cells containing data will be selected.
Page 5 of 16
Lab Experiment | 4
9. The Excel SORTBY function sorts the contents of a range or array based on the values from another
range or array. The range or array used to sort does not need to appear in results.
We wish to sort the city names in ascending order of the zip addresses. Use the following function to
execure this:
=SORTBY(E2:E49,G2:G49)
Where E column contains city names and G column contains zip codes. Try repeating this in
descending order.
10. The VLOOKUP function allows searches across columns. It is used very commonly to lookup relevant
data for computation. Enter the function below in cell J3 (or in any empty cell as per your worksheet.
=VLOOKUP(J2,A2:G49,6,FALSE)
The value you want to search is entered separately in another cell, in this case J2. The search is carried
out in the array provided in next argument, in this case A2:G49. The result generated is from column 6,
which is the state where the person belongs to. FALSE implies that we want an exact match. Note that
VLOOKUP searches vertically in a column and the data provided to search should always belong to the
first column. A sample image is shown below:
11. A very similar function, HLOOKUP, works in a similar way. However, it matches the provided value in
a row. Write the function below the previously written VLOOP function as also shown in the picture
below:
=HLOOKUP(J4,A2:G49,11,FALSE)
Where the first argument J4 refers to the cell where value to be searched is inserted. A2:G49 refers to
the array to be searched. If the value is matched, the result from the row 11 will be presented. FALSE
implies the same meaning as before. It is important to note that VLOOKUP is used much more
frequently that HLOOKUP in practice because usually the data is entered in spreadsheets in such a way
that each row contains 1 record and columns contain properties of records. Therefore, we are usually
interested in finding a property that matches a record (using VLOOKUP) and not the record which has
matching property (using HLOOKUP).
Page 6 of 16
Lab Experiment | 4
12. Another variant for searching data in arrays is XLOOKUP. With XLOOKUP, you can look in one
column for a search term and return a result from the same row in another column. Insert the function
below in the cell under HLOOKUP results as also shown in picture below:
=XLOOKUP(J6,A2:A49,G2:G49)
13. Now we practice last exercise for this worksheet before moving to another spreadsheet. Notice that
when you scroll down, the first row doesn’t move. You can make the first row freeze or the first column
freeze or any set of rows or columns freeze from the View tab. A picture is shown below for reference:
You can also hide rows and columns and later unhide them if you want something not to be visible.
Select one or multiple rows or columns and right click on them. Choose the Hide/Unhide option there.
Page 7 of 16
Lab Experiment | 4
Task 3:
1. Open the Excel file CSC101_Lab_Handout_4_US_Car_Data.xlsx provided separately with the lab
handout. The Excel file contains data of cars sold in USA. Note that the first row is not frozen, you may
freeze the first row as explained earlier if you wish. However, what you must do is to select all columns
of the first row and apply filter on it as shown in picture below:
Note that now when you click any column in the first row, it allows you to filter or choose data as per
your wish in a very convenient manner as shown below for first column.
Page 8 of 16
Lab Experiment | 4
2. When we receive any file that contains large amount of data, the first step is typically to clean the data.
We will attempt to find duplicate entries in the data. For this purpose, several approaches are commonly
used. One approach is to highlight duplicate values under ‘Conditional Formatting’ option. Make sure
you select the relevant column first where you are suspicious that duplicate entries can be identified.
You can now see duplicate values highlighted. You can delete the rows if you want to remove it.
3. Press CTRL+Z to undo the deleted rows and highlighting so that we can use other methods to find
duplicates. To find duplicates using COUNTIF, follow these steps.
Add an extra column, next to ‘Model’ column where you suspect repetition can occur.
In the first cell of the new column, write function with following template: (note that the function
below assumes that Model column belongs to column A, and all models are written from range 2 to
13. You should adjust your formula to accommodate your worksheet)
= IF(COUNTIF($A$2:$A$13,A2)>1,”Yes”,””)
This is an important exercise to look into how IF and COUNTIF functions work.
Drag the formula below to copy it in all rows containing Model data.
You can now delete duplicate rows, that are specified with ‘Yes’ text.
4. Undo the changes again to use the final method to delete duplicates. Go to the Data tab and look for
‘Remove Duplicates’ option. This automatic tool is applied on all rows that have same data.
Page 9 of 16
Lab Experiment | 4
5. The worksheet contains a lot of data and it is not easy to understand everything it contains. In this
regard, it is convenient to somehow present brief portion of the data. Make another copy of ‘Car_sales’
worksheet and call it ‘Slicer_1’.
6. In Slicer_1 worksheet, go to Insert tab and click on Slicer button. The Slicer slices your data and uses
the whole display area to show only the data that you have sliced.
A new dialog box will ask you to select columns that you want to slice.
Choose the 3 options as shown above and click OK. You will now see 3 columns that you selected in
individual dialog boxes.
Page 10 of 16
Lab Experiment | 4
Experiment by clicking on ‘Car’, ‘Model’ and ‘Unit Sales’ options available and observe how you are
presented only a slice of information based on your selection. You can also select multiple options in 1
column by clicking on .
8. Another way to contain data in concise manner is by using pivot tables. The pivot table is under the tab
Insert as shown below:
Press the PivotTable icon and choose pivot table From Table/Range option.
The PivotTable will automatically select the table in the worksheet as shown below. However, if it does
not, select all the data in the worksheet.
Page 11 of 16
Lab Experiment | 4
Click OK and new worksheet will be created. You have to populate the newly created pivot table by
choosing appropriately choosing data to include.
The settings chosen as shown on right of the above picture produces a table on the left. You will be able
to observe that it presents the data in much more concise manner. As an exercise, click on various fields
to add in the pivot table and drag the fields between ‘Rows’, ‘Values’, ‘Columns’, ‘Filters’ boxes and
change their order to observe how pivot table changes.
Now, choose the following columns in PivotTable Fields:
Page 12 of 16
Lab Experiment | 4
In the Values section, instead of showing Sum of Price, we will instead prefer to show Average of
Price. Follow the steps below to do so:
Page 13 of 16
Lab Experiment | 4
9. Repeat this step for Year Resale Value to show its average instead of its sum. Now you will observe
that you are being shown the average values instead of their sums as shown below:
10. Click on any cell with data and go to Insert tab to insert Slicer. Select Car option only.
Now that you also have a slicer, you can choose only the data you want to be shown.
Page 14 of 16
Lab Experiment | 4
11. Additionally, you can go to Insert tab and insert a chart as shown below and use the slicer to show data
of your choice.
Page 15 of 16
Lab Experiment | 4
The student performance for the assigned task during the lab session was:
The student completed assigned tasks without any help from the
Excellent 4
instructor and showed the results appropriately.
The student completed assigned tasks with minimal help from the
Good 3
instructor and showed the results appropriately.
The student could not complete all assigned tasks and showed
Average 2
partial results.
Worst The student did not complete assigned tasks. 1
Page 16 of 16