04. Excel Countif and Vlookup
File -> Open -> 04b-datastart.xlsx
Click on new tab icon to insert new sheet
Conditional Formatting
Select Sheet1
Select Column G
We want to highlight any cells with a P/E greater than 15
Select Home -> Conditional Formatting
Format cells greater than 15
Click OK
Any P/E greater than 15 is highlighted
Challenge Highlight any cells with a Price less than 50
Count, Sum, Average Max, Min
Insert new sheet
Want to find summary stats for Market Cap Type in the following headings
Click Formulas -> AutoSum -> Count Numbers
Inserts the COUNT function
Tell Excel what column you want to count: Go to Sheet 1 and select Column E
Select Column E
Press Enter on keyboard
There are 2496 companies with market capitalisation information in dataset
Select next cell
Select Formulas -> AutoSum -> Sum
Tell Excel what to Sum: Select Sheet1 then Column E and press Enter
Have now calculated the total market capitalisation of all 2496 companies
Challenge For market capitalisation calculate: – Average – Maximum – Minimum
Countif and Sumif
We sometimes want summary statistics for different groups e.g. countries
Type in these headings
Select Cell D8, for Countif DE
Select Formulas -> More Functions -> Statistical -> COUNTIF
For Range choose Sheet1 Column D to count the number of observations per country
Click Column D
Click Criteria
For Criteria choose the cell with the country name
Click OK
There are 683 companies from Germany (DE)
For cell E8 select Formulas -> Math & Trig -> SUMIF
For Range choose Sheet1 Column D
Select Column D
Click Criteria
For Criteria choose the cell with the country name
Click Sum_range
For Sum_Range choose Sheet1 Column E as it contains market capitalisation
Select Column E
Click OK
Calculates the total market capitalisation of companies based in Germany
Challenge For France, Britain and Ireland use: – Countif to calculate number of companies in each country – Sumif to calculate the total market capitalisation of these companies in each country
Vlookup
Select Sheet2
Sometimes we want to extract data from one list into another
Type in the full names of a number of companies featured in main dataset
We want to obtain P/E and TotalReturn data for these companies
Click Formulas -> Lookup & Reference -> VLOOKUP
Lookup_value -> Click on your first company’s name
Click on Table_array -> Then open Sheet1 containing data
Select Column headings B to I
Click on Col_index_num and type 6
Click on Range_lookup and type false
Click OK
We have now extracted the P/E ratio for BP from our main dataset
Analyse the VLOOKUP formula to understand how it works
A5 is the value that we want to search for Sheet1!B:I is the dataset that we look in (the first column of your dataset should always be the one which contains the name you are looking for) 6 is the column number in the dataset that we want to find False is whether we will accept approximate matches
File -> Save As -> 04c-datacompleted.xlsx
Challenge Use Vlookup to obtain TotalReturn for your company Repeat for some other companies