Excel Basics To Advanced - Design Robust Spreadsheet Applications Powered With Formatting
Excel Basics To Advanced - Design Robust Spreadsheet Applications Powered With Formatting
Basics to Advanced
Design Robust Spreadsheet Applications
Powered with Formatting, Advanced Calculations, Charts, Pivot
Tables, and Macros.
Chandraish Sinha
www.ohiocomputeracademy.com
Legal Notes
Copyright © 2023 Books District Publication.
First Edition.
ISBN: 978-0-9992449-6-8
All rights reserved. No part of this book may be reproduced,
stored in a retrieval system, copied, printed, modified, or shared
by any means without prior written permission of the
author, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made to make this book as complete and
accurate as possible. However, there may be mistakes, both
typographical and in content. The information contained in this
book is sold without warranty, either express or implied.
Neither the author nor publisher will be held liable for any
damages caused or alleged to be caused directly or indirectly
by this book.
The content in the book should be used only as a general guide
and not an ultimate source for MS Excel implementations.
Some topics may seem similar to other published sources, but this is only due to the
commonality presented by the topics.
Dedicated to
Ishie
My daughter, who excels in every little thing she does…
About the Author
Chandraish Sinha is the Founder/President of Ohio Computer Academy, a company
dedicated to IT education.
An IT training enthusiast, Chandraish resonates with his company’s slogan - Inspire, Educate
and Evolve. He is a Business Intelligence learner and explorer, with a strong background in
implementing multiple large and medium-scale BI solutions.
Throughout his 22-year career, Chandraish has worked with a variety of Business
Intelligence and dashboarding applications, such as Tableau, Power BI, Qlik View, Qlik
Sense, IBM Cognos, Business Objects, and Actuate. His passion for data leads him to
explore applications that provide better data insights.
Chandraish is an accomplished author with multiple published books on various topics. To
view his Amazon author profile, visit amazon.com/author/ chandraishsinha.
He actively maintains his blogs, where he regularly shares insights and knowledge on
applications such as MS Excel, Tableau, Power BI, and QlikView. Readers can find his blogs
at the following links:
• https://ohiocomputeracademy.com/category/msexcel/
• https://ohiocomputeracademy.com/category/tableau/
• https://ohiocomputeracademy.com/category/power-bi/
• https://www.learntableaupublic.com/
• https://www.learnallbi.com/
Connect with him on LinkedIn: www.linkedin.com/in/chandraishsinha
Other books by the author:
1. Dashboarding with Tableau
2. Mastering Power BI
3. Tableau Unlimited
4. Implementing Tableau Server
5. Tableau 10 for Beginners
6. Tableau Dashboards: Step by Step guide to developing visualizations in Tableau 9.2
7. Tableau Questions & Answers: Guide to Tableau concepts and FAQs
8. QlikView Essentials
9. QlikView Questions and Answers: Guide to QlikView and FAQs
10. How to be a Successful IT Professional in the USA: A Checklist and Easy Guide
to Success
Acknowledgement
My earnest thanks to all my readers who have supported my books so far and inspired
me to pursue further. I personally read all their reviews and feedback.
I am grateful to the entire Microsoft community at large for creating numerous blogs,
videos, and other content. They provide immense learning and exploring opportunities.
I extend my sincere thanks to my students for asking challenging questions and
encouraging me to learn more.
Book writing involves the effort of many people, and I am thankful to all of them for
providing the necessary assistance.
Preface
Microsoft Excel is the popular application due to its versatile features and capabilities. Its useful
features, data manipulation capabilities, PivotTables, and powerful functions empower users to
efficiently organize, analyze, and present data in various formats.
Having worked in different Business Intelligence applications, including Tableau, Power BI, and
Qlik, I've come to realize that Excel is the building block for BI and data analysis. In fact, these
applications heavily rely on Excel. Additionally, organizations use Excel to test the reports and
dashboards designed in these applications.
Excel is essential for anyone starting a career in Information Technology, as it forms the basis of
databases and helps in understanding how functions work in calculations.
This book introduces readers to the basics and gradually advances to deeper concepts. A sincere
attempt has been made to cover all the aspects of MS Excel from start to finish.
The technique I have followed in this book is to explain the concept followed by a hands-on
exercise. All the data and solution files are provided. Readers can follow the steps provided in
the book and create their own spreadsheets.
This book can be used with any version of Excel. The basic workings of Excel have not changed
over the years, but new features get added with the newer versions.
The goal of this book is to provide readers with a comprehensive and practical resource that will
not only improve their Excel skills but also empower them to leverage Excel as a valuable tool in
personal and professional endeavors. I have taken care to explain concepts in a clear and
straightforward manner, making this book suitable for both self-study and as a reference guide.
Over the 11 chapters in this book, you will learn the following:
Chapter 1 covers the basics of MS Excel and explains all the
important terminologies. It assists in installing the application and provides detail
explanations of the ribbon and other functionalities such as Sorting, Filtering, Printing and
more.
Chapter 2 explains how to format data in an Excel spreadsheet. It also covers conditional
formatting in Excel.
Chapter 3 Introduces the readers to the formulas and calculations. It also explains the
concept of different types of cell references and their usefulness in creating calculations.
Chapter 4 deals with Logical functions and how they are used in performing logical tests
using IF, AND, and OR functions.
Chapter 5 discusses Text functions in Excel and how to perform string manipulation using
functions like LEFT, RIGHT, LEN, CONCAT, and more.
Chapter 6 explains DateTime functions in Excel. It starts with how dates are represented in
Excel and how to use different date functions.
Chapter 7 takes a deep dive into Mathematical functions such as COUNT, SUM, SUMIFS,
and more.
Chapter 8 covers in detail the Lookup and Reference functions such as VLOOKUP,
LOOKUP, INDEX, and MATCH.
Chapter 9 explains Pivot tables and charts. Pivot tables are essential for aggregating and
analyzing data, and charts are used to present data visually.
Chapter 10 covers Excel tables, which provide added functionality on the range of cells. It
explains how to create an Excel table and use to them to analyze the data.
Chapter 11 introduces Macros in Excel, which are used to automate the repetitive tasks.
The chapter explains how to record and run a Macro.
https://ohiocomputeracademy.com/ms-excel-basics-to-advanced/
Password: MS@Excel
Errata
In creating this work, any unforeseen errors might have occurred. If any readers encounter
difficulties due to processing errors, please write to us at:
[email protected]
with subject line: Errata Excel Basics to Advanced
Your support, suggestions, and feedbacks are highly appreciated by the Author.
He personally reads and responds to all messages.
Table of Contents
1.MS Excel Fundamentals
Introducing MS Excel
Importance of MS Excel
MS Excel Terminology
Installation
Installation of Office 365
Understanding the ribbon
Ribbon Tabs
Understanding the Workbook
Creating your first Workbook
Auto fill
Flash fill
Copy data from one sheet to another
Saving the Excel Workbook
Freeze Pane
Sorting
Filtering the data
Task bar
Printing in Excel
Printing Options
2.Formatting in Excel
Cell Formatting in MS Excel
Format Cells
Conditional Formatting
Custom Conditional Formatting
3.Introduction to Formulas
Overview of Formulas
Cell Reference
Relative Cell reference
Absolute Cell reference
Mixed Cell reference
3-D reference
R1C1 reference
Copy values of a Formula
4.Logical Functions
Overview of Logical Functions
The IF function
The AND function
The OR function
The NOT function
The IFERROR function
5.Text Functions
Overview of Text Functions
The LEFT, RIGHT, and MID function
The LEFT function
The RIGHT function
The MID function
The LEN function
The CONCAT function
6.DateTime Functions
Overview of Dates
Add or subtract days from dates
The EDATE function
The DATE, YEAR, MONTH, and DAY functions
The DATE function
The YEAR function
The MONTH function
The DAY function
Calculating Quarters
TODAY, NOW, and TIME functions
TODAY and NOW functions
The TIME function
7.Mathematical Functions
The COUNT functions
COUNT function
COUNTA function
COUNTIF function
The SUM functions
SUM function
SUMIF function
SUMIFS function
8.Lookup and Reference
The VLOOKUP function
How it works
VLOOKUP features
Look up value in the same sheet
Look up value in different sheets
Look up value in different workbooks
The LOOKUP function
The INDEX function
The MATCH function
Combining INDEX and MATCH function
9.Pivot tables and Charts
Understanding Pivot Tables
Pivot Table Interface
Creating Pivot table
Charts in Excel
Standard Charts
Pivot Charts
Updating PivotTable Data
Updating the PivotTable with New Data Rows
Automatically Updating the PivotTable on open
10.Excel Table
Overview of Excel Tables
Creating an Excel table
SubTotal function
SUBTOTAL vs. SUM
11.Introduction to Excel Macros
Overview of Macros
Enabling the Developer tab
Recording a Macro
Visual basic code for Macros
Index
Chapter 1
MS Excel Fundamentals
MS Excel or Microsoft Excel is a popular spreadsheet application that empowers users to
organize, analyze, and manipulate data efficiently. This chapter will begin by exploring the user
interface, including ribbon, Worksheets, and Cells. Additionally, it will cover data entry and
demonstrate how to perform filtering and sorting operations.
The following topics will be discussed in this chapter:
Introducing MS Excel
Installation
Understanding the ribbon
Understanding the workbook
Creating your first Excel workbook
Freeze Pane
Sorting
Filtering the data
Task bar
Printing in Excel
Introducing MS Excel
MS Excel stands for Microsoft Excel, is a spreadsheet program developed by Microsoft
Corporation. It is a part of the MS Office suite of business applications and enables users to
format, organize, and perform calculations on data in a spreadsheet format. Excel was first
launched in 1985.
Importance of MS Excel
MS Excel is utilized by organizations in a variety of ways. Some of the usages of MS excel
include:
Data storage: MS Excel's vast grid allows for storing large amounts of data,
making it ideal for data storage purposes.
Data validation: The built-in functionalities in MS Excel facilitate quick and
efficient data validation.
Data analysis: Excel's ability to generate reports and charts makes it valuable for
data analysis tasks.
Creating wireframes: Excel can be utilized to create wireframes for website
designs and dashboard layouts.
Day-to-day tasks: MS Excel is handy for various day-to-day tasks like creating
attendance reports, accounting, and time management.
Basis for learning other applications: Proficiency in MS Excel can serve as a
foundation for learning other tools and applications, including database
management and reporting platforms like Tableau and Power BI.
MS Excel is a powerful and versatile spreadsheet application that plays a crucial role in various
organizations and industries. Moreover, MS Excel serves as a stepping stone for learning more
advanced applications and tools, making it an essential skill in today's data-driven world.
MS Excel Terminology
A good knowledge of the terminology and keywords used in MS Excel are essential in order to
master the application. Some common terms are listed in Table 1.1 MS Excel Terminology,
below.
Table:1.1 MS Excel Terminology.
Terminology Description
Workbook A design file created in Excel is called a Workbook. One
workbook can contain multiple worksheets.
Worksheet An individual spreadsheet in a workbook.
XLS/XLSX The commonly used extensions of an Excel file are XLS/XLSX.
XLS is the default file format from Excel 97-2003, and XLSX is
the default format for Excel 2007 and later.
Data Data entered on a spreadsheet can be a number, text, or an image.
Rows/Columns The data in a worksheet is stored in row and column format. Rows
are horizontal, and columns are vertical.
Cell The data is entered/stored in a cell, which is an intersection of a
row and column.
Cell reference It is a combination of row (number) and column (letter) that
/address identifies the position of a cell on a spreadsheet.
Formula Uses the built-in functions in Excel and perform computations
such mathematical, string, logical, etc.
Pivot table A Pivot table is used to summarize the data present in the
spreadsheet.
Pivot charts The graphical representation of the summarized data is done using
charts.
Sort Arranging the data based on the value or the data type.
Filter A Filter is used to display the data based on the specified criteria.
Macro A Macro is a series of recorded or manually written commands
that automate repetitive tasks within Excel.
Understanding the key terminology and concepts in MS Excel is crucial for effectively using the
application. Having a grasp of these fundamental Excel terms provides a solid foundation for
working with spreadsheets.
Installation
Installation of MS-Excel is required to perform the exercises provided in this book. MS Excel is
part of MS Office applications, these applications come in two flavors:
For the exercises in this book, readers can use either version of MS Office, but having MS Excel
installed is necessary to follow along and practice the concepts explained throughout the
chapters. The installation steps for both are the same.
3. Depending on the browser used to download Office 365, select Run (in Microsoft edge or
Internet explorer), Setup (in chrome), or Save File (in Firefox).
4. On the prompt Do you want to allow this app to make changes to your device, select Yes.
This will start the installation process.
5. Once the installation is complete, a message will be displayed on the screen, “You’re all
set! Office is installed now.” An animation will be played to show where to find
Microsoft 365 applications on the computer.
6. Select Close.
7. To open Microsoft 365 apps, select the Start button on your machine and type the name
of the app, such as Excel.
8. When the app opens, accept the license agreement.
Note: To launch MS Excel on the machine, click on the Windows button and type Excel.
In addition to these shortcuts, there are numerous shortcuts available to access specific
commands within each tab.
Understanding the Workbook
In MS Excel, a Workbook consists of one or more Worksheets, also referred to as Sheets or
spreadsheets. Each Worksheet is a separate tab within the Workbook and can contain different
sets of data or information.
The structure and important components of a workbook are shown below.
Auto fill
Instead of manually typing data in each row/cell, use the AutoFill option to enter data more
effortlessly.
AutoFill works on cells that follow a pattern, for example, the Row ID and Order Date columns.
The Row ID column contains consecutive numbers (1, 2, 3, 4), and the Order Date column
contains the first date of every month. However, AutoFill cannot be used on the Ship Date
column, as it does not have any pattern.
Exercise2: Using the Auto fill feature, fill the remaining Row IDs 3 through 12. Also, use this
option on Order Date to fill the continuous dates.
Steps to use the Auto fill feature:
1. In the worksheet, select the Row ID values 1 and 2, then use the fill handle (plus + sign)
on the bottom right corner of the cell, and drag it down to fill the remaining Row IDs
from 3 to 12.
Flash fill
Flash fill is a new feature in Excel 2023. It automatically fills the data in a column based on
patterns it identifies in the adjacent cells. For example, Flash fill can be used to separate the first
and second names from a single column or combine the first and second names from two
different columns.
Exercise3: Using the Flash fill functionality, split Ship Mode into two separate columns.
Currently Ship Mode contains two words, for example, ‘Priority Delivery’; the objective is to
separate these values into two columns.
Refer to Chapter1.MSExcelFundamentals_Solutions (Sheet EnteringData_FlashFill) for the
solution.
Steps to use the Flash fill:
1. In the worksheet created previously, insert two blank columns after the Ship Mode
column. To do this, follow these steps:
This will result in two blank columns being inserted after the Ship Mode column.
2. After inserting the two blank columns after Ship Mode column, provide the headers of
these new columns as Ship Name1 and Ship Name2.
3. In the Ship Name 1 column, type the first name ‘Priority’ in the first cell. Then, use the
right-click of the mouse and drag down from the edge of the cell to select Flash Fill.
This will fill in the corresponding Ship Name1 values automatically based on the pattern
it identifies.
Figure 1.7: Flash Fill for Ship Name1.
4. Similarly, in the Ship Name2 column, type the second name ‘Delivery’ in the first cell.
Then, use the right-click of the mouse and drag down from the edge of the cell to select
Flash Fill. This will fill in the corresponding Ship Name2 values automatically based on
the pattern it identifies.
5. To combine the columns again, insert a column after Ship Name2. Name this column
header as Ship Mode Combined.
In the first cell, type the combined name of the first Ship Mode – ‘Priority Delivery’.
Then, use the right-click of the mouse and drag down from the edge of the cell to select
Flash Fill. This will fill in the corresponding combined Ship Modes automatically based
on the pattern it identifies.
Figure 1.8: Flash fill output of Ship Mode.
Flash Fill can be used with any text values that follow a recognizable pattern. It automatically
detects and fills the adjacent cells based on the identified pattern, making data manipulation and
formatting more efficient.
The option Move or Copy as shown in Figure 1.9 is used to move or copy the
spreadsheet within the existing Workbook. Try this option and observe the results.
Saving the Excel Workbook
To save the file for the first time, navigate to File option from the ribbon and select Save As. This
option is used to save the file in the desired location. If the file is already saved, then use Ctrl + S
keys on the keyboard to update the file in the existing location with the current changes made.
To save the workbook, navigate to File menu and select Save As. Then, select Browse to
navigate to the desired location.
Sorting
Sorting is the process of arranging a group of data in a specific order. In Excel, sorting can be
performed on:
Sorting options are available in the Home tab under Editing group or from the Data tab under
Sort & Filter group (ALT + A + S).
Exercise6: In the previously saved workbook, sort the data first by Ship Mode in ascending
order (A to Z), then by Segment in descending order (Z to A), and finally by Region in ascending
order (A-Z).
Steps to perform Sorting using multiple columns:
1. Navigate to the Data tab in the ribbon and select Sort.
Sort By: Select Ship Mode from the dropdown to specify on which column
the sorting will occur.
Sort On: Select Cell Values to specify how the sorting will be performed,
i.e., on the cell Values or color.
Order: Select A to Z to specify the sort order i.e., ascending or descending.
In this option, Custom List is used to specify the user-defined sorting
pattern.
Use Add Level to add other columns in the sorting, such as, Segment and Region,
and select the appropriate settings.
The Sort settings should appear as shown below:
Figure 1.19:
Filtered data.
Task bar
The taskbar or status bar in an Excel spreadsheet is located at the bottom of the Excel window. It
provides useful information and quick access to various functionalities. Taskbar displays the
following:
Ready status. The leftmost section typically displays "Ready" when Excel is idle
and ready to receive user input.
Sum, Average, Count. When range of cells containing numerical data is selected,
Excel automatically shows the sum, average, and count of the selected cells on the
bottom-right of the status bar.
Zoom slider. The slider on the right end of the status bar allows users to adjust the
zoom level of the worksheet.
Page Layout and Normal View. Displayed on the right of the status bar. Clicking
on these icons allows users to switch between these views for the worksheet.
Printing in Excel
Printing data in an Excel worksheet allows users to produce hard copies of their spreadsheet for
various purposes, such as reports, and presentations or data analysis. Entire or partial worksheet
and workbooks can be printed. A Workbook can also be print to a file instead of a printer.
Printing Options
Several settings are available to print the data on an Excel worksheet. From the File menu in the
ribbon, navigate to Print to view all the settings. The advantage of this option is that the user can
see the preview of the data as they adjust the settings.
The shortcut to invoke the Print options is CTRL + P.
Figure 1.21: Print settings.
Table 1.3 Print settings explains the various options for printing Excel data.
Table:1.3 Printing options.
Printing Description
Setting
Print Active Use this option to choose whether you want to print the entire workbook,
Sheets the active sheet, or a selected area in the worksheet.
Print One sided Use this option to specify whether you want to print only on one side of
the paper or on both sides.
Collated Refers to the way multiple copies of a document are arranged when
printed. When you print multiple copies of a worksheet or workbook, the
collate option determines whether the copies are printed sequentially or
grouped together.
Portrait Use this option to specify the orientation of the printed document –
Orientation Portrait or Landscape.
Letter This option is used to specify the size of the printed page.
Normal By looking at the preview of the data, you can adjust the margins of the
Margins document.
No scaling The Scaling option can be used to specify how the data is to fit on a
sheet while printing.
Page Setup This option can be used to specify header and footer to the document
while printing.
There are different print settings available to print data in an Excel worksheet. These options are
also available from the ribbon’s Page Layout tab.
Chapter 2
Formatting in Excel
The previous chapter provided an introduction to the fundamentals of MS Excel. This chapter
will explore formatting in MS Excel, starting with basic cell formatting such as changing colors,
fonts, and number formatting. In addition to the fundamental formatting options, the chapter will
delve into conditional formatting, an advanced feature that enables automatic formatting based
on specific conditions.
The following topics will be discussed in this chapter:
Cell Formatting
Conditional formatting
To clear the applied formatting, navigate to Home tab and select Clear from the Editing group.
Format Cells
Format cells option can be applied to a specific cell or multiple cells in a worksheet. It is invoked
by right-clicking on any cell and selecting Format Cells or by using the dialog box launcher
(small downward arrow) on the Number group on the Home tab. The shortcut to invoke the
Format Cell option is CTRL + 1.
The tabs on Format Cells can also be accessed from the Home tab ribbon under the groups for
Font, Alignment, and Number.
3. Select the header row again, and from the Home tab, under the Font group, select
Borders and then All borders. This will produce borders around each cell in the
header row.
4. Group the headers using merge cells.
- Insert a blank row above the header row by selecting the header row, right-clicking,
and selecting Insert.
- In the new row, type Order Details in the cell with address B1 (first row, B
column).
- Select columns B1 through E1, and from the Home tab, select Merge & Center
(from the Alignment group).
Figure 2.3: Merging cells.
This will display the text Order Details in the center of the selected cells.
To learn more details about the options used in MS-Excel to perform this formatting,
select Order Details, right-click, and choose Format Cells.
- Similarly, type Customer Details in cell F1.
Select cells F1 through I1 and from the Home tab, select Merge & Center (from
Alignment group).
- Type Metrics in cell J1.
Select cells J1 through M1 and from the Home tab, select Merge & Center (from
Alignment group).
- Use different colors to differentiate the groups.
The Profit column should also have the same format as Sales. To do this, follow these
steps:
- Select any cell in Column J (Sales)
- Go to the Home tab, find Format Painter icon in the Clipboard group, and click on
it. This will copy the formatting of the selected cell.
Figure 2.6: Selecting Format painter.
- Now select or drag over all the values in Column M (Profit). This will apply the
format of the Sales column to the Profit column.
Tip: If user click on the Format Painter once, it will copy the formatting, which can only be
pasted once. To paste the formatting at multiple locations, click on the Format Painter, then click
on the desired locations. If user double-click on the Format Painter icon, the formatting can be
pasted at multiple locations with clicking again. To reset the copied formatting at any time, press
the Esc key on the keyboard.
7. Formatting Discount column to display as a percentage (%).
Select Column L (Discount) and from the Home tab, navigate to the Number group, then
click on the % icon to format the values as percentages.
Formatting of data is essential to ensure that the data entered is displayed in the intended format.
To review or change the format, right-click on the cell and select Format Cells.
Conditional Formatting
Conditional formatting in Excel allows users to apply formatting to the data based on specific
criteria. It is similar to Cell formatting but more dynamic as it is based on conditions.
Conditional formatting options are available from the Home tab under Styles, in the Conditional
Formatting group.
Figure 2.7: Conditional Formatting options.
The shortcut to invoke the Conditional Formatting options is ALT + H + L.
MS Excel provides predefined conditional formatting options such as Highlight Cells Rules,
Top/Bottom Rules, etc. Custom rules can be defined by using the New Rule option. To reset the
formatting options, select Clear Rules.
Exercise2: Perform the following formatting options in the worksheet
data.
- Display the Sales amount in Green where Sales is greater than $500.
- Display negative Profits in red.
- Display Top 20% of Profit in green.
- Display data bars to represent higher and lower quantities sold.
- Display Sales Score card to depict Low, Medium, and High sales amounts in red,
yellow, and green, respectively.
Refer to Chapter2. FormattingInExcel_Solutions (Conditional Formatting sheet) for the
solution.
Steps to perform Conditional formatting:
1. Use the previously saved sheet. Either make a copy of it or work on the same sheet.
2. Display Sales in Green.
- Select Column J (Sales). From the ribbon, navigate to Home> Styles > Conditional
Formatting.
- From Conditional Formatting, select the option for Greater Than. In the Greater
Than dialog, specify the condition for greater than 500 and choose the color Green
fill with Dark Green Text.
Steps shown as 1 and 2 in the figure below.
- Select Column M (Profit). From the ribbon, navigate to Home> Styles >
Conditional Formatting.
- From Conditional Formatting, select the option for Highlight Cells Rules and
then choose Less Than and in the Less Than dialog box, specify the condition
for negative values.
- Select Column M (Profit). From the ribbon, navigate to Home> Styles >
Conditional Formatting.
- From Conditional Formatting, choose the option for Top/Bottom Rules and choose
Top 10%.
- In the Top 10% dialog box, specify the condition for 20% and change the color to
Green fill with Dark Green Text.
For this example, copy the Sales column into an empty column after Profit and name it
as New Sales. This is done so that the previous formatting is not disturbed.
- Select New Sales column and from Conditional Formatting, choose Clear Rules
and then select Clear Rules from Selected Cells. This will remove all the previous
formatting.
- With the New Sales column selected, from Conditional Formatting, choose the
option for Color Scales and select the first color scale.
Figure 2.12: Use color scales to display the Scorecard.
This will display high Sales in Green, medium in Yellow, and lower Sales in red.
1. Select the data portion of Column G (Segment), i.e., G3 to G38. Navigate to the
Home tab and then click on Conditional Formatting > New Rules.
2. Under the New Formatting Rules box, select the last option Use Formula to
determine which cells to format.
3. Under Edit Rule description, type the formula,
=$J3 > 500
The above steps are shown in the figure below as Step1, Step 2, and Step 3.
Overview of Formulas
Cell reference
Copy values of a formula
Overview of Formulas
A formula in Excel is a mathematical expression that performs calculations or actions on the data
present in the worksheet.
A formula can be written in any cell and always starts with an equal (=) sign
followed by an expression. After typing the formula, press the Enter key on the
keyboard to execute it.
A formula can contain a mathematical operator (+, -, /, *) or an Excel- defined
function (Sum, Average, Min, Max, etc.).
If functions are used in a formula, they are always enclosed within a pair of
parentheses ( ).
A formula in a cell can be used with autofill to compute the formula for all the rows
and columns.
To execute/finalize a formula, press Enter on the keyboard. To exit from the
formula cell. press the ESC key on the keyboard.
A formula can contain a cell address, a range of cells (vertical or horizontal), a
function, a mathematical operator, or a constant.
For example, the following formula:
=SUM(C3:C14) * 2
uses Sum function to add the values contained in the cell range C3 through C14 and
finally multiplies it by a constant 2. A constant is a number or text values entered
directly into a formula, and these values do not change.
When a Formula is typed, it appears in the formula Bar at the top of the sheet. To
view a formula, select a cell containing the formula, and it will be displayed in the
formula bar.
Tip: Formulas usually refer to a range of cells. To select all the cells in a column, click on the
first cell and then press CTRL+ SHIFT and the down arrow on the keyboard.
- Using the mouse, Autofill (click on the cell and drag it down from the edge) the rest
of the cells to perform the calculation for rest of the rows.
3. Calculate the Total Hourly Wage.
- Navigate to cell B15 and type the Text Total.
- On cell C15, type “=”, and then type the function, Sum. Since it is a function, it
should be enclosed in parenthesis, type “(“. We can press Tab on the keyboard after
typing =Sum.
- Using the mouse, select the range on Column C (Hourly Wage).
- Close the parenthesis and press Enter.
Figure 3.2: Calculating the Sum.
4. Calculate Maximum Hourly Wage.
- In cell B16 type the Text Max.
- In cell C16, type “=Max(” (or press Tab on your keyboard after typing =Max).
- Using the mouse, select the range in Column C (Hourly Wage).
- Close the parenthesis and press Enter. The maximum hourly wage will be displayed
in cell C16, and the formula should look like the following:
=MAX(C3:C13)
7. Calculate Total, Max, Min and Average for the Pay column.
- Copy the formulas performed previously in columns C15, C16, C17, and C18.
- Select cell F15 and paste the copied formulas in F15. Excel will automatically
adjust the cell references for F15, F16, F17, and F18 to reflect the appropriate
values from the Pay column.
After performing the above calculations, the worksheet will look like the one shown
below:
Refer to previous exercise Step 4. Pay was calculated using the formula =C3*D3 in cell F3.
When the formula is auto filled in the remaining columns, Excel automatically changed the
reference to the respective cells.
Figure 3.4: Relative Reference.
Click on each cell to check the formula. When the Total, Max, Min, and Average calculations
were copied and pasted (previous exercise Step 7), relative referencing was used again.
Tip: To display the formula used in the entire sheet, use the Show Formula toggle located in
Formulas > Formula Auditing on the ribbon. This will switch between the actual formula and the
resulting value.
After typing the formula, press Enter. Then, use the autofill handle to fill the formula in
the rest of the cells in Column G. All the values will be calculated correctly. This can be
checked by selecting each of the cells to verify the calculations.
3. Now to get the values for the week starting 23-Jun, perform Autofill horizontally.
Tip: To add a $ sign for mixed reference, first type the regular calculation, and then in the
formula bar, add $ before the respective column or row.
Now, perform autofill both vertically and horizontally for all the weeks. The correct values
will be displayed. The usage of $F3 in the formula will keep the column F constant and
change only the rows, allowing the calculations to be correctly applied.
The final output will appear as shown below:
Figure 3.9: Final output with Absolute column Mixed reference.
This modification will keep the Pay column (C) constant while allowing the row to
change as the formula is copied or auto filled to other cells.
Now, perform autofill horizontally to get the correct amounts for Rent and Movies. The
formulas for Rent will appear like =$C6*D2 and for Movies, it will appear as =$C6*E2.
5. Calculate remaining values.
Now, to calculate the values for all the employees, select the cells D6, E6, and F6 and
drag them down to autofill in all the cells for different employees.
This will display incorrect results.
3-D reference
3-D reference allows referencing cells in multiple worksheets.
For e.g., a workbook contains 5 sheets, namely, Sheet1, Sheet2, Sheet3, Sheet4, and Sheet5.
Each of these sheets contain a cell for Total (which is stored in cell G5). A 3-D reference can add
all of these totals from different sheets. The syntax will be:
=Sum(Sheet1:Sheet5!G5)
Exercise4: Use the enclosed Chapter3. IntrotoFormula_2.xlsx. It has four sheets containing the
monthly payroll information for employees. The structure of all the sheets is the same and each
one contains a total in Cell C14.
- Calculate the Total of all the months, taking the Totals from Cell C14 in each of the
sheets.
Refer to Chapter3. IntrotoFormula_2_Solutions.xlsx for the solution.
In the formula, June:Aug represents the range of the sheets, and C14 is the cell where
the total in each sheet is calculated.
R1C1 reference
In Excel, cell addresses can be represented in two ways: A1 style and R1C1 style. In R1C1
reference style:
Both the row and column of a cell address are referred by a number.
In A1 style, the first row is denoted by number 1, and the first column is denoted by
the letter A. In R1C1 style, both the first row and the first column are represented
by R1C1, where both the row and column are referred to by a number.
By default, Excel uses A1 style. To change to R1C1 style, navigate to File >
Options > Formulas and check R1C1 reference style.
Figure 3.14: Option to change A1 style to R1C1 style.
- Click on cell K2, type “=”, and then type IF. Press Tab on the keyboard. It will
display = IF( . The syntax of the calculation will also be shown.
- Select Column J2 (Sales) and type the calculation as
=IF(J2>500,"High","Regular")
This calculation will evaluate the condition J2>500; if it is true, “High” will be
displayed; otherwise “Regular” will be displayed.
3. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
3. After the first value is displayed correctly, drag it down to autofill the rest of the cells.
4. Using IFS function.
Go to Column U/IFS (cell U2) and type the formula as shown below:
=IFS(G2 = "Home Office","$2",G2 = "Corporate","$3",G2 = "Consumer","$4")
In the above IF function, the AND function is used as a logical test. If it evaluates to
true, it returns “20% Bonus”; otherwise, it returns false, returns “TBD”.
5. Autofill the rest of Column L with this new calculation.
This formula will return “True” if either the Ship Mode (Column D2) is “Priority
Delivery” or Sales (Column J2) is less than 100.
The calculation on cell M2 will return True as one condition (Ship Mode = Priority) is
true.
3. Autofill the remaining cells of Column M with this formula. Based on the condition
specified in the formula, several Trues and Falses will be displayed.
4. Use OR with IF.
Modify the calculation on M2 to enclose the OR function within the IF function.
=IF(OR(D2="Priority delivery",J2<100),"Shipping Charge", "No Shipping Charge")
In the above IF function, the OR function is used as a logical test. If it is true, it returns
“Shipping Charge”, if false, returns “No Shipping Charge”.
Notice that it uses the reverse of the earlier IF function (specified in Exercise 1). The
NOT function checks if Sales in not greater than 500 and uses the IF function to display
Regular and High.
3. Autofill the remaining cells in Column N. It will produce the same result as in
Column K.
4. Using NOT to check multiple values.
To use NOT for checking multiple values, use it in conjunction with AND or OR
function.
- On Cell 02 (NOT with multiple values), type the calculation as:
=IF(NOT(AND(G2="Home Office",H2="West")),J2,0)
This calculation will check if Segment is not “Home Office” and Region (H2) is not
“West”, then displays Sales(J2), else displays 0.
Figure 4.4: Result of NOT function.
The NOT function offers flexibility and enhances the capabilities of Excel when dealing with
various data scenarios.
3. Autofill the remaining cells in Column P. Notice the error #DIV/0!; it is a divide-by-0
error as some of the discount values are 0%.
The IFERROR function in Excel is a valuable tool for handling errors that may occur in
formulas. It provides a way to catch and manage errors, ensuring that the spreadsheet remains
accurate and functional even in the presence of errors.
Chapter 5
Text Functions
The previous chapter provided an explanation on Logical functions and how to use them in
checking conditions in a calculation. This chapter will explore the use of Text functions in Excel.
Text functions help in extracting specific parts of a text, combine text from different cells,
finding the length of text, remove unwanted characters, and much more.
The following topics will be discussed in this chapter:
This calculation will start from the left side of Order ID and extract 2 characters.
3. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
4. RIGHT function.
Navigate to Column D (Order Number) and type the calculation on cell D2:
=RIGHT(B2,6)
This formula will start from the right and will extract 6 characters. Autofill the rest of
the cells.
5. MID Function.
This formula will start from the position 4 and return 4 characters.
After implementing all the three functions, the result will appear as below:
=LEN(D2)
This will calculate the length of the Order Number stored in Cell D2. Autofill the rest of
the cells in Column D
3. Finding the length of a Date.
Navigate to Column H and type the formula as on cell H2:
=LEN(G2)
This will calculate the length of Order Date stored in Cell G2. Autofill the rest of the
cells in Column H.
Notice that Excel avoided the data formatting characters (/) while calculating the length
of date.
4. Finding the length of a Number.
Navigate to Column P and type the formula as on cell P2:
=LEN(O2)
This will calculate the length of Sales stored in Cell G2. Autofill the rest to the cells in
Column P.
Notice Excel considers the $ sign and space while calculating the length of the number.
In this way, Order numbers having length greater than 6 will be marked as “Incorrect”.
=CONCAT(D2,"-”,E2,"-",UPPER(LEFT(M2,3)))
The formula will work as follows:
Select D2
Concatenate it with “-“
Select E2
Concatenate it with “-“
The LEFT (M2,3) will take three letters of Region from the left and use UPPER to
convert them to upper case letters.
Finally, CONCAT will concatenate all the strings present in the calculation.
The CONCAT function allows users to create new text strings by joining multiple text
values without the need for complex formulas or manual string manipulation.
Chapter 6
DateTime Functions
The previous chapter provided an explanation on Text functions and how to use them to perform
operations on string values. This chapter will explore the use of DateTime functions. These
functions enable users to perform tasks like calculating the difference between two dates,
extracting the day, month, or year from a date, adding or subtracting time intervals, and
converting date formats.
The following topics will be discussed in this chapter:
Overview of Dates
Adding or subtracting days from dates
The EDATE function
The DATE, YEAR, MONTH, and DAY functions
Calculating Quarters
TODAY, NOW, and TIME functions
NETWORKDAYS function
Overview of Dates
Dates are essential for data storage and analysis as they help in tracking the data by dates.
In an Excel cell, a date is stored as a serial number, but the cell formatting displays
it in the date format.
The time portion present in the date is represented as decimals.
Dates stored as serial numbers allow performing numerical calculations on dates.
The default date format is m/d/yyyy. Excel dates start from January 1, 1900 and the
serial number of the date ‘1/1/1900’ is 1, ‘1/2/1900’ is 2, and so on.
The date format and serial number can be checked by typing 1, 2, etc. in any cell
and formatting it to date.
Dates can be formatted in different ways by using Format Cells.
When filters are applied, an aggregated date format is displayed.
- Click on cell C2, type “=” and then select cell D2 (Order Date), add minus sign “-“
and type 7. The formula should appear like:
= D2-7
3. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
4. Navigate to Column G (Survey Date).
- Click on cell G2, type “=” and then select cell D2 (Order Date), add plus (+) and
type 3. The formula should appear like
= D2+3
5. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
- Click on cell H2, type “=” and then type the function EDATE. Press Tab on the
keyboard. This will display opening parenthesis and the syntax of the function.
- Select cell D2 (Order Date) and type comma “,”, and then type 3. The formula
should appear as
=EDATE(D2,3)
3. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
Figure 6.3: Adding Dates using EDATE.
To subtract a specific number of months from the date, use a negative number in the
calculation.
- Click on cell I2, type “=” and then type the function DATE. Press Tab on the
keyboard. This will display opening parenthesis and the syntax of the function.
- Type YEAR and press Tab, select D2 and add (+1) to it. Type a “,” after this.
- Type MONTH and press Tab, select D2 and add (+2) to it. Type a “,” after this.
- Type DAY and press Tab, select D2 and add (+15) to it. Type a “,” after this.
- Close the parenthesis and press Enter.
- The formula should appear as:
Calculating Quarters
Calculating Quarters in Excel requires using the MONTH and ROUNDUP functions. Excel does
not have a direct function to calculate a Quarter, so it is derived from the MONTH and
ROUNDUP functions.
The ROUNDUP function is used to always round up to the nearest number of decimal places.
Syntax:
=ROUNDUP (number, num_digits)
Where:
Number is the number to be rounded up and num_digits is the number of decimal places to
which the number should be rounded up.
For example, =ROUNDUP(67.57,1) will round up the number to 67.6, and
=ROUNDUP(67.57,0) will round up the number to 68.
- On Cell J2, type “=” and then ROUNDUP, press the Tab key on the keyboard.
- To supply the number to the ROUNDUP function, type “MONTH(“ and either
type D2 or select the cell D2 and type “/3”.
- Type “,” , and type 0. This will roundup the number to 0 places of decimals.
The resulting formula will appear as:
=ROUNDUP(MONTH(D2)/3,0)
3. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
In the above formula, NOW() will provide the system’s date and TIME function will add the
hours, minutes, and seconds to it.
NETWORKDAYS function
The NETWORKDAYS function in Excel is used to calculate the number of working days
between two specified start and end dates, excluding weekends and specified holidays. It
includes both the start date and end dates in the calculation. This function is useful for
calculating the number of days while excluding non-working days.
Syntax:
=NETWORKDAYS(start_date,end_date,[holidays])
Where:
Start_date. The start date in the range.
End_date. The end date in the range.
Holidays. Optional. A list of dates that are considered holidays and should be excluded from the
count. A range of cells containing the holiday dates must be provided.
=NETWORKDAYS (D2,F2)
3. After the first value is displayed correctly, drag it down to autofill the rest of the
cells.
This will provide the working days between the two dates.
Chapter 7
Mathematical Functions
The previous chapter explained DateTime functions and their application in date calculations. In
this chapter, the focus is on the essential Mathematical and Statistical functions in Excel,
specifically delving into aggregation functions like COUNT and SUM.
The following topics will be discussed in this chapter:
COUNT functions
SUM, SUMIF, and SUMIFS functions
COUNT function
The COUNT function counts the cells that contain numbers, dates, and numbers formatted as
Text. It does not count the blank cells, error values, text values, and logical values.
Syntax:
=COUNT(value1, value2..)
It can also accept a range of cells, for example, =Count(A2:A10)
COUNTA function
The COUNTA function is similar to COUNT but can count error values, text, and logical values
in a cell. It does not count the blank cells.
COUNTIF function
The COUNTIF function counts only the cells that meet a certain criterion.
Syntax:
=COUNTIF(range, criteria)
Where:
Range is the range of cells and criteria is the condition specified in double quotes. For example,
= COUNTIF(A2:A10, “>5”)
SUMIF function
The SUMIF function is used to add the values in a range that meet specific criteria.
Syntax:
SUMIF(range, criteria, sum_range)
Where:
Range is the range of cells on which the criteria will be applied. Criteria is the condition which
can be a number, expression, cell reference, text, or a function. Sum_range is optional and
specifies the actual cells to be added. If omitted, Excel adds the cells that are specified in the
range.
SUMIFS function
The SUMIFS function adds the values in the cells meeting multiple criteria.
Syntax:
SUMIFS(sum_range, criteria_range1, criteria1, criteria_range2, criteria2,…)
This formula will display the sum of all the cells in column J.
3. Calculating Total Sales for the Region = West .
The function SUMIF will be used since this calculation requires a condition.
- Navigate to cell J22. Type =SUMIF, and then press tab on the keyboard.
- Select the range of cells in column H (Region),
- Provide the criteria for Region West and select the range of cells where Sum
needs to be applied, i.e., column J.
- The completed formula should appear as:
=SUMIF(H2:H19,"West",J2:J19)
The VLOOKUP and LOOKUP are reference functions used to reference data stored in the same
or different sheets/workbooks.
How it works
The VLOOKUP function works by searching for the "Value to look up" in the first column of the
specified range "where this value is located."
Once it finds a match, it returns the value from the specified "column number" in that range.
The "return an Approximate or Exact match" is indicated as 1/TRUE for an approximate match
or 0/FALSE for an exact match.
VLOOKUP features
It is useful in situations where one table/range contains an ID, and another
table/range contains the corresponding ID/description. VLOOKUP can reference
both tables, match the IDs, and return the corresponding descriptions.
VLOOKUP searches for values to the right of the lookup value. It looks for the
lookup value in the first column of the table/range and then searches to the right. It
cannot search to the left of the lookup value.
If the range_lookup parameter (true/false) is TRUE or not provided, the first
column in the table/range needs to be sorted alphabetically or numerically.
If the first column is not sorted, it may return unexpected values. To ensure an exact
match, either sort the first column or use FALSE as the range_lookup parameter.
Steps to use VLOOKUP when lookup value is located in the same sheet:
1. Open Chapter8.LookupAndReference.xlsx.
2. To get Customer Name.
1.
a. Navigate to cell G2.
b. Type = VLOOKUP and press the tab key on the keyboard.
c. Select Cell F2 (Customer ID) to provide the lookup value,
d. Select the range F14:G25 to provide the table array (where Lookup value
and description is located)
e. Type 2 to provide the col index. It is 2 because the range F14 to G25
contains only 2 columns, the first one being the lookup value.
f. Close the parenthesis and press Enter.
= VLOOKUP(F2,F14:G25,2)
This will produce incorrect results as the Customer ID column in the table_array
(F14:G25) is not sorted and no value (true/false) is provided for the range_lookup.
To get the correct value, we need to either sort the Customer ID column in the
table_array or provide FALSE in the range_lookup to get the exact match.
Modify the VLOOKUP formula to provide FALSE.
=VLOOKUP(F2,F14:G25,2,FALSE)
3. If the value in G2 is correct, autofill the rest of the cells to fill the formula for the
remaining cells in column G. This will apply the VLOOKUP formula to all the
customer IDs in column F and automatically retrieve the corresponding customer
names in column G.
Figure 8.1: Finding Customer Name using VLookup.
4. To get Product Name.
a. Navigate to Column K (Cell K2). Write the VLOOKUP formula as:
=VLOOKUP(J2,J14:P25,4,FALSE)
In the above formula, note that col_index is specified as 4, which is the column
number where the Product Name(located at M14) is found (starting from Product
ID as the first column.)
5. If the value in cell K2 is correct, autofill the formula to the rest of the cells in
Column K. This will populate the Product Names for all corresponding Product
IDs.
Figure 8.2: Finding Product Name using VLookup.
Observe that the range is displayed with the sheet name Customers ! A1: B12
3. If the value in G2 is correct, autofill the rest of the cells in Column G. Excel will
automatically apply the VLOOKUP formula to the subsequent cells, adjusting the
cell references accordingly, and display the corresponding Customer Names for
each Customer ID.
Figure 8.3: Customer Names displayed from a different sheet.
4. To get Product Name.
The Customer Name and Product Name values will be the same as displayed in the
previous exercises.
Syntax: =
=LOOKUP(lookup_value, lookup_vector, [result_vector])
Where:
lookup_value: is the value that needs to be looked up.
lookup_vector: The one-row or one-column range to search.
result_vector: The one-row or one-column range of results.
VLOOKUP vs LOOKUP
Both functions are used for looking up the values, but VLOOKUP is more suited when the
search is made across multiple rows and within specific columns. VLOOKUP searches on the
right, the lookup column needs to be the first column in the range. On the other hand, whereas
LOOKUP (in Microsoft 365 XLOOKUP) can look up values in any direction, allowing for more
flexibility in searching.
Where lookup value is B2, B2:B6 is a range where the lookup value is located, and
C2:C6 is the range where the lookup_vector or the searched value is located.
3. Age of ID 23948
4. Name of ID 14872
Observe in this formula, LOOKUP is looking to the left of the lookup value, which is
not possible using VLOOKUP.
5. Phone number of ID 27361
- Navigate to cell F14 (or any cell of your choice) and write the formula using the
INDEX function
=INDEX(A1:O12,5,6)
In the above formula A1:O12 is the range, number 5 is the row number, and 6 is the
column number. This formula will return DM-12955.
2. Return the value when only one column (F) is selected as a range.
- Navigate to cell F15 (or any cell of your choice) and write the formula using the
INDEX function:
=INDEX(F1:F12,5)
In the above formula F1:F12 is the range of the Column F. Since only one column is
selected, only the row number 5 is specified, and the column number is omitted. This
formula will return DM-12955.
3. Return the value when only one row (5) is selected as a range.
- Navigate to cell F16 (or any cell of your choice) and write the formula using the
INDEX function
=INDEX(A5:O5,6)
In the above formula A5:O5 is the range of the row 5. Since, only one row is selected,
only column number 6 is specified, and row number is omitted. This formula will return
DM-12955.
Figure 8.6: Result of the INDEX function.
Due to its ability to work with entire ranges, individual columns, or rows, the INDEX function
provides users with flexible options for data lookup and reference.
- Navigate to cell I14 (or any cell of your choice) and write the formula using the
MATCH function
=MATCH(G8,G2:G12,0)
In the above formula, G8 is the lookup value (Brian DeCherney). G2:G12 is the
range that contains this lookup value. 0 is the match type, which means an exact
match should be used.
The result of the above expression is 7. This indicates that Brian DeCherney is
located at the 7th position in the range G2:G12.
- Navigate to cell L14 and write the formula using the INDEX function:
=INDEX(G1:L12,2,6)
This will return the Sales of 475.944 for Customer - James Lanier.
2. Use the MATCH function to find the position of the Sales
- Navigate to cell L15 and write the formula using the MATCH function:
=MATCH(L2,L1:L12,0)
This will return the position of Sales 475.944 i.e., 2.
3. Combining the INDEX and MATCH function in one calculation.
Pivot table is created by selecting Insert > Pivot Table from the ribbon.
Pivot Table Interface
The data contained in Chapter9.PivotTable (Sheet SourceData) is utilized to illustrate the Pivot
table interface.
The steps to be followed to create a pivot table are:
This section displays all the fields available in the selected data. As fields are selected,
they will appear in the view. Fields can be dragged/dropped under Filters, Columns,
Rows and Values as needed. To access field properties, click on the drop-down arrow
next to the respective field.
b. Filters.
The fields dropped here will serve as filters for the view/report.
c. Columns.
The Pivot table displays data in a column and Row format. Drop the fields that want to
be displayed in columns here.
d. Rows.
e. Values.
a. PivotTable Analyze. Use this option to add Slicer to the Pivot table.
Additionally, find Calculations, Charts, and Recommended PivotTables options
available here. If the underlying source data changes, refresh the Pivot table by
selecting the Refresh option.
b. Design. Use this option to control the layout, including Subtotals, Grand
Totals, Report Layout, Blank Rows, as well as PivotTable Style options.
The formatting of a PivotTable can be done in the same fashion as with any other cell or sheet in
Excel.
Exercise1: Use the enclosed Chapter9.PivotTable (Sheet SourceData) to perform this exercise.
- Create a Pivot table to display Sales by Customers and count the number of Orders for
each Customer.
- Use the Order Date to filter data by Years.
- Format Sales with a $ sign and show two decimal places.
- Display the Top 10 Customers by Sales.
Refer to Chapter9.PivotTable_Solutions.xlsx (Sheet PivotTable2) for the solution.
Exercise2: Use the enclosed Chapter9.PivotTable (Sheet SourceData) to perform this exercise.
- Create a Pivot table to display Sales by Category and Sub-Category. Display Subtotals
and Grand Totals.
- Use the Order Date to place a filter for Years.
- Calculate the Percentage of Sales for each Category and Sub-Category.
- Display a calculated field to calculate Cost as Sales/Quantity.
- Filter the results by Year = 2019, and Category = Furniture.
Refer to Chapter9.PivotTable_Solutions.xlsx (Sheet PivotTable3) for the solution.
Steps to create a PivotTable to find the Sales by Category and SubCategory.
1. In the Chapter9.PivotTable.xlsx workbook, navigate to the sheet named SourceData.
2. From the ribbon, navigate to the Insert tab. Then, from the PivotTable drop-down, select
From Table/Range.
Choose the default range and make sure to use the option for New WorkSheet. This will
display the PivotTable interface on a new sheet.
3. From the PivotTable Fields:
- Select the fields Order Date, Category, Sub-Category, and Sales.
- Except for the Years (Order Date), remove all the other date fields. These fields
can also be removed from the bottom of the field list.
- Move Years (Order Date) from Rows to the Filters section.
This will display Years (Order Date), Category, Sub-Category, and Total on the
Pivot table. It also displays Sub-totals by Category.
- With the PivotTable selected, navigate to Design option in the ribbon and explore
the options for Subtotals and Grandtotals.
- If Subtotals are not displayed, select the option Show all Subtotals at the bottom of
Group.
4. Calculate Percentage of Sales by Category and Sub-Category .
- In the PivotTable Fields, drag Sales from the field list to the Values section. It will
appear as Sum of Sales2.
- Click on the drop-down arrow next to Sum of Sales2 and select Value Field
Settings. In the dialog box, click on the tab Show Values As and from the drop-
down list under Show Values as, select % of Parent Row Total.
Charts in Excel
Charts in Excel are visual representations of data that make it easier to understand and analyze
complex information. Excel offers a wide variety of chart types, such as bar charts, column
charts, line charts, pie charts, scatter plots, and more, allowing users to choose the best-suited
chart for their data.
Excel has two types of charts – Standard Charts and Pivot chart. Most of the functionalities are
similar between the two charts except for few differences.
Standard Charts vs Pivot charts
1. Standard charts are created from the Insert tab, in the Chart group on the ribbon.
Pivot Charts are created from the Insert tab, in the Chart group (PivotChart) on the
ribbon. PivotCharts can also be created from PivotTable Analyze option, which is
displayed once PivotTable is selected.
2. Standard charts are connected to the source data/ worksheet cells. Pivot Charts are
based on the PivotTable data source (PivotTable fields).
3. Using Standard charts any kind of charts can be created. However, PivotCharts
cannot create Scatter or Stock charts.
Standard Charts
Standard charts are created from the Insert tab, in the Chart group on the ribbon. These charts
are connected to the source data/ worksheet cells.
To create a chart:
Select the data or range to visualize, then click on the "Insert" tab in the Excel
ribbon and navigate to the Charts group.
Choose the desired chart type for Excel to automatically generate the chart based on
the selected data.
Excel also provides Recommended Charts option, based on the data present in the
sheet.
The chart can be customized to suit the requirements. Excel provides options to add
titles, labels, data labels, legends, and even change the chart's colors and styles.
Excel's intuitive interface allows for quick chart creation and customization, enabling users to
add titles, labels, and other elements to enhance the visual representation.
Exercise3: Use the enclosed Chapter9.PivotTable (Sheet SourceData) to perform this exercise.
Create a copy of the SourceData sheet and perform the following:
- Create a bar chart to display top 10 customers by sales.
Refer to Chapter9.PivotTable_Solutions.xlsx (Sheet Std_SourceData) for the solution.
Steps to create Standard bar Chart:
1. In the Chapter9.PivotTable.xlsx workbook, navigate to the sheet named SourceData and
make a copy of the sheet. Name this sheet Std_SourceData.
2. Select the Sales column (Column N) and then go to the Home tab in the ribbon and
navigate to Sort & Filter option in the Editing group.
3. Choose the option for Sort Largest to Smallest, and in the subsequent box, select Expand
this selection. This will display top 10 customers by sales.
4. Now, select the column/ranges that will be used to create the chart. From the Customer
Column (column G), select G1 thru G11. Press CTRL on the keyboard and select the
corresponding Sales, i.e., cells N1 though N11.
5. Go to Insert tab on the ribbon and from the Charts group, either choose the
Recommended Charts, or select the drop down next to the bar chart icon and choose the
bar chart.
Pivot Charts
To create a Pivot chart, we need to first create a Pivot table as they are based on the PivotTable
data source.
Exercise4: Use the enclosed Chapter9.PivotTable (Sheet SourceData) to perform this exercise.
- Create a Pivot table to display Sales by various Regions.
- Use the Order Date to place a filter for Years.
- Create visualizations, such as bar charts, pie charts etc., to display this data.
Refer to Chapter9.PivotTable_Solutions.xlsx (Sheet Charts) for the solution.
Steps to create a PivotTable and Charts.
1. In the Chapter9.PivotTable.xlsx workbook, navigate to the sheet named
SourceData.
2. Creating Pivot table.
- From the ribbon, go to the Insert tab, select Pivot Table, and choose the default
range. Create a Pivot table on a new sheet.
- In the PivotTable Fields, select Order Date. It will be displayed under the Rows
section. Remove all the other date fields except Year (Order Date) and move it to
Filters.
- Select Region and Sales. Region will be displayed in the Rows, and Sales will be
displayed in the Values section.
- Select all values under Sales in the PivotTable and change the formatting to display
a $ sign in front of the numbers.
Rename this sheet as RegionWise Sales.
The PivotTable will appear as shown below:
Figure 9.16: PivotTable for Region-wise Sales.
- Click anywhere on the PivotTable, go to the PivotTable Analyze tab in the ribbon.
From the Tools group, select PivotChart.
- By default, a chart will be selected (e.g., Clustered Column).
Pie charts should display percentage of total instead of the whole amount.
i. In the chart, right-click on the pie slices and select Add Data
Labels.
ii. Right-click on the slices again and select Format Data Labels.
To change the chart type, right-click on the existing chart and select Change Chart Type
to choose a different chart for data representation.
Default Header row. By default, a table has a header row. Each header column
displays a drop-down for filtering and sorting. When creating a table, users can
specify if the data contains headers. If this option is not selected, Excel
automatically creates a default header row.
Visible header row. In a large dataset, the header row is always visible.
Banded row. By default, all rows in the table are displayed with shading or banding
to distinguish the rows of data.
Table Design. When a cell inside a table is selected, the ribbon displays Table
Design. It can be used to control the properties of the table by selecting/unselecting
them.
Total row. When the Total Row option is selected from Table Design, it adds a row
with Totals. The cells on the total row display a drop-down to perform calculations
such as Average, Count, Sum, etc. When one of these options is selected, Excel
automatically converts them to a SUBTOTAL function, which ignores the filtered
rows while performing the calculation.
Automatic addition of Row/Column. To add a new row, navigate to the last cell and
press the Tab key on the keyboard. To add a new column, simply start typing a
column header next to the last column in the table, and a new column will be added
automatically.
Automatic Autofill. When a calculation is created in a cell of a column, it is
automatically filled in all the cells of the column. Autofill is not required.
Slicer option. To further filter the data, Excel Tables provide the option to add a
Slicer from the Insert tab. Slicers allow users to visually filter data in the table.
Resizing of Table. The last cell of the table displays a sizing handle that can be
used to drag and increase the size of the table.
Dynamic Pivot Table/Charts. When an Excel table is used as the source data for a
Pivot Table/Chart, it refreshes dynamically when data updates or a new row is
added, ensuring that the Pivot Table/Chart always reflects the most recent data.
Excel Tables provide added functionalities as compared to regular data in the range of cells.
Creating an Excel table
An Excel table is created from a range of cells. Data from any worksheet can be converted to an
Excel table.
Exercise1: Use the enclosed Chapter10.ExcelTable (Sheet SourceData) to perform this exercise.
- Convert the Source Data to an Excel table.
- Add a new Calculation in Column 0 as New Sales = Sales * Discount
Refer to Chapter10.ExcelTable_Solutions.xlsx (Sheet Table) for the solution.
Steps to create an Excel Table:
1. Open Chapter10_ExcelTable.xlsx and navigate to the sheet SourceData.
2. Make a copy of the Source Data sheet to preserve the original data for comparison.
a. Right-click on the Source Data sheet and select Move or Copy, then choose
(move to end) from the list. Select the option Create a copy at the bottom.
b. Rename the new sheet as Table.
a. Select any cell within the data range, then go to the Insert tab in the ribbon and
click on Table. The Create Table dialog will appear with the range of the cells
pre-selected. Make sure to check the option My table has headers.
Figure 10.1: Create Table option.
This will create an Excel table with headers and banded rows.
Once the Table is created, it will display the Table Design option on the ribbon. On the
extreme right, it shows the Table name. The default Table name can be changed here.
4. Add a calculation for New Sales .
a. Navigate to cell O2. Type “=” and create the calculation by selecting K2,
typing “*” and then selecting M2.
b. Press Enter. The formula in the cell O2 will be auto-filled to all the cells in
column O.
c. Rename the Column as “New Sales”.
Exercise2: Use the enclosed Chapter10.ExcelTable (Sheet SourceData) to perform this exercise.
- Convert the Source Data to an Excel table.
- Add a Table row to display the Total of Profit and Average of Sales.
- Check the difference between SUBTOTAL and SUM functions.
Refer to Chapter10.ExcelTable_Solutions.xlsx (Sheet Table2) for the solution.
Steps to create an Excel Table with a Total row:
1. Open Chapter10_ExcelTable.xlsx and navigate to the sheet named SourceData.
2. Make a copy of the Source Data sheet to preserve the original data for comparison.
Rename the new sheet as Table2.
3. Create an Excel Table.
- Select any cell within the data range. Go to the Insert tab in the ribbon and click on
Table. The Create Table dialog will appear with the range of the cells pre-selected.
Make sure to check the option My table has headers.
4. Add a Total row .
- Click on any cell in the Table, and from the Table Design option in the ribbon,
select Total Row.
Figure 10.4: Total Row in the Table Design option.
This will display the Total label under the first column and Total amount under the last
column, i.e., Profit.
Notice that a dropdown is displayed on every cell in the Total row, which shows
different aggregation functions. Any function can be selected from the dropdown, and it
will automatically perform the calculation.
a. Navigate to cell N14 and create the SUM (Profit) formula by typing =SUM
(and selecting all the cells in the Profit column.
At this point, both SUBTOTAL and SUM will show the same amount as
$399.86
Now, filter the data on Region = Central.
The SUBTOTAL amount will change to $6.51, but the Sum will stay the same as
$399.86.
Excel tables provide an efficient way to manage data. They are particularly useful when dealing
with large datasets to perform data analysis. They offer added functionalities and features
compared to regular data ranges, making data manipulation and calculations more convenient
and efficient.
Chapter 11
Introduction to Excel Macros
The previous chapter provided an explanation of Excel Tables and how they can be used
organize data in the worksheet. This chapter will focus on the usage of Excel Macros. Macros are
powerful tool that automate repetitive tasks and enhance productivity. The chapter will delve into
recording and running a macro, as well as exploring the VBA editor for editing and enhancing
macro code.
The following topics will be discussed in this chapter:
Overview of Macros
Recording a Macro
Editing the Visual Basic code for Macro
Overview of Macros
A Macro is a series of recorded or manually written commands that automate repetitive tasks
within Excel.
Recording a Macro
Macros are designed to automate repetitive tasks in Excel, saving time and effort for the user.
The process of creating a macro involves three main steps: recording the macro, stopping the
recording, and running the recorded macro.
The following exercise will create a macro to automate the formatting of data, which will
streamline the formatting process and enhance productivity.
- Navigate to the Developer tab in the ribbon and select Record Macro.
- Provide the name of the Macro as Format_Sales_Profit.
Figure 11.3: Recording a Macro.
- Perform conditional formatting to display Sales >500 in Green .
Highlight the Sales column and navigate to Home > Conditional
formatting.
Select the option Highlight Cells Rules and choose Greater Than. Specify
the condition as 500:
4. After completing the above tasks, navigate to the Developer tab in the ribbon and
click on Stop Recording. This will stop the recording of the macro.
5. Run the macro.
a. To observe the running of Macro, create another copy of the
SourceData sheet and name it RunMacro.
b. Navigate to the Developer tab and select Macros. The subsequent
dialog will display all the Macros created so far. Select
Format_Sales_Profit and click Run.
Figure 11.6: Executing the Macro.
This will execute the Macro and format the Sales and Profit
columns as desired.
6. Save the file as an Excel Macro-Enabled Workbook (.XLSM) so that the Macro
remains attached to it. Save the file as Chapter11.IntroMacros_Solutions.xslm.
Excel macros are sets of recorded or manually written commands that automate repetitive tasks
in Excel. Excel macros are a powerful tool to simplify complex tasks, automate repetitive
actions, and maintain consistency in data formatting and processing across different files.
Index
A
Auto fill, 27
C
Cell reference
3-D reference, 78
Absolute Cell reference, 66
Mixed Cell reference, 71
R1C1 reference, 80
Relative Cell reference, 65
Charts in Excel, 174
Copy data from one sheet to another, 31
D
DateTime functions
Calculating Quarters, 119
DATE function, 114
Dates, 109
DAY function, 116
EDATE function, 113
MONTH function, 116
TIME function, 124
TODAY and NOW functions, 122
YEAR function, 116
E
Excel Tables
Creating an Excel table, 187
Overview of Excel Tables, 184
SubTotal function, 189
F
Flash fill, 28
Formatting
Conditional Formatting, 51
Custom Conditional Formatting, 57
Format Cells, 46
I
Importance of MS Excel, 15
Installation, 17
L
Logical functions
AND function, 89
IF function, 85
IFERROR function, 95
Nested IF and IFS, 87
NOT function, 92
OR function, 90
Lookup and reference functions
INDEX function, 153
LOOKUP function, 149
MATCH function, 156
VLOOKUP
Look up value in different sheets, 142
Look up value in different workbooks, 146
Look up value in the same sheet, 138
VLOOKUP
VLOOKUP function, 135
M
Macros
Overview of Macros, 193
Recording a Macro, 196
Visual basic code, 200
Mathematical functions
COUNT function, 126
COUNTA function, 128
SUMIF function, 131
SUMIFS function, 131
P
Pivot tables
Creating Pivot table, 166
Pivot Tables
Pivot Charts, 178
Understanding Pivot Tables, 161
Updating PivotTable Data, 181
Printing, 42
R
Ribbon
Ribbon Tabs, 20
Understanding the Ribbon, 18
S
Saving, 34
T
Terminology, 15, 16
Text function
CONCAT function, 106
Text functions
LEFT function, 99
LEN function, 103
MID function, 99
RIGHT function, 99
W
Workbook
Creating your first Workbook, 24
Understanding the Workbook, 23