Today we’re going to learn about some features of Excel and how they interact.
- Tables and how they’re named
- SUMIF
We’re going to do this with a little problem our hypothetical boss has given us. It’s the end of the first quarter. She would like to know how much each client has paid us for this quarter.
We’re going to get all of this information from a little ledger she sent us. She’s no Excel expert, but she’s meticulous about records. This means we have plenty to work with just from this little table.
Date |
Client |
Source |
Work Type |
Payment |
1/2/2017 |
Hogwarts |
Nepotism |
IT Consulting |
$ 1,729.00 |
1/4/2017 |
Torchwood |
Advertising |
Copywriting |
$ 2,020.00 |
1/9/2017 |
Bene Gesserit |
Competitive Bid |
Training |
$ 1,900.00 |
1/9/2017 |
The Royal Frog Trampling Institute |
Competitive Bid |
IT Consulting |
$ 3,829.00 |
1/11/2017 |
The Monitor’s Guild |
Competitive Bid |
Training |
$ 4,983.00 |
1/31/2017 |
Church of All Worlds |
Competitive Bid |
IT Consulting |
$ 4,422.00 |
2/1/2017 |
Torchwood |
Advertising |
Training |
$ 1,772.00 |
2/3/2017 |
Council of Elrond |
Advertising |
Training |
$ 1,029.00 |
2/3/2017 |
The Royal Frog Trampling Institute |
Competitive Bid |
Training |
$ 2,063.00 |
2/5/2017 |
Church of All Worlds |
Competitive Bid |
Copywriting |
$ 2,929.00 |
2/8/2017 |
Hogwarts |
Nepotism |
Copywriting |
$ 1,943.00 |
2/8/2017 |
The Monitor’s Guild |
Competitive Bid |
Training |
$ 3,872.00 |
2/10/2017 |
Bene Gesserit |
Competitive Bid |
IT Consulting |
$ 5,026.00 |
2/14/2017 |
The First Order |
Nepotism |
IT Consulting |
$ 2,032.00 |
2/28/2017 |
Xavier Institute for Gifted Youngsters |
Nepotism |
Training |
$ 3,098.00 |
3/2/2017 |
Bene Gesserit |
Competitive Bid |
Training |
$ 4,465.00 |
3/5/2017 |
Torchwood |
Advertising |
Copywriting |
$ 1,072.00 |
3/5/2017 |
Torchwood |
Advertising |
Training |
$ 1,943.00 |
3/6/2017 |
Hogwarts |
Nepotism |
IT Consulting |
$ 2,063.00 |
3/7/2017 |
The Royal Frog Trampling Institute |
Competitive Bid |
IT Consulting |
$ 2,972.00 |
3/8/2017 |
Torchwood |
Advertising |
Copywriting |
$ 3,872.00 |
3/13/2017 |
Bene Gesserit |
Competitive Bid |
Training |
$ 5,026.00 |
3/15/2017 |
Hogwarts |
Nepotism |
IT Consulting |
$ 1,072.00 |
3/16/2017 |
Hogwarts |
Nepotism |
Training |
$ 2,075.00 |
3/30/2017 |
The Royal Frog Trampling Institute |
Competitive Bid |
IT Consulting |
$ 3,141.00 |
4/2/2017 |
The Monitor’s Guild |
Competitive Bid |
Copywriting |
$ 1,772.00 |
This is just a ledger that records the date, the client, how we got the client, what work we did for the client, and how much we were paid.
The first thing we will do is turn this array into a table. This will make the rest of the calculations easier.
Tables in Excel
To turn an array into a table in Excel:
- Select the range you would like to make a table. (For the purposes of this exercise, that’s going to be cells A1:E27)
- On the Home tab in the Styles group, click on Format as Table.
- Choose the table style you would like.
- Make sure that in the Format as Table dialog box, the My table has headers checkbox is checked.
- Click OK.
You have now formatted your array as a table. This is more than pretty formatting, however, but also means you have created an object with some specific functions.
Before we get to the problem our boss has asked us to solve, I want to do one more thing – name the table. If you are going to be using more than one table in a spreadsheet, and will be performing calculations from more than one table, it is a good idea to give each table a meaningful name. While we are not going to go quite that far in this exercise, it’s a good general habit.
To Name a Table in Excel:
- Make sure a cell in the table is selected.
- Look at the top of your screen at the different tabs for ribbons. The last one should be Design with a Table Tools as a label above it. Click on it.
- On the Table Tools:Design ribbon in the Properties group, you will see a Table Name text box.
- Type the name you want for your table and press <Enter> on your keyboard. (We’re calling this table “Ledger”)
Now that we have formatted the array as a table, we are going to look back at what our boss wants.
The first thing she wants is how much each client has paid. We will start by creating another little array. Then we will use the SUMIF function to add up how much each client has paid us. As we go through this, you will see why I prefer to do this as a table rather than just keeping the array as-is. For the purposes of this exercise, we’re presuming that we’ll be starting an array to the side of the Ledger table starting in cell G1. The formula we will use in cell H2 will be:
=SUMIF(Ledger[Client], G2, Ledger[Payment])
Let’s break this down, as it might look like gobbledygook at first.
The function we will use is SUMIF, so we start with =SUMIF.
The syntax for the Sumif function is:
=SUMIF(range, criteria, sumrange)
So, the range is the comparison. In this case, we want the function to look in the Client column of the Ledger table, which is written as Ledger[Client], with the table name and the column name in brackets right beside it.
Then we want to know the criteria for comparison. There are a couple of ways to do this. You could look for specific text by putting it in quotes. So, we could have written it as “Bene Gesserit” (You put quotes around text you’re searching for). Which begs the question, why did I use the cell reference G2 instead? Well, mostly because I am lazy. I want to be able to write this equation once, then use autofill to complete the rest of the array.
The last thing we want to know is where to look for the values for which we want a total. In this case it is in the Payment column of the Ledger table, so we use Ledger[Payment].
Client |
Total |
Bene Gesserit |
=SUMIF(Ledger[Client], G2, Ledger[Payment]) |
The Royal Frog Trampling Institute |
|
Torchwood |
|
The Monitor’s Guild |
|
Hogwarts |
|
Church of All Worlds |
|
Xavier Institute for Gifted Youngsters |
|
The First Order |
|
Council of Elrond |
|
Pop quiz. If I did not set this up as a table, but left the array as-is, could I have used cell references instead?
My word, yes. In this particular example,
=SUMIF(Ledger[Client], G2, Ledger[Payment])
would become:
=SUMIF($B$2:$B$27, G2, $E$2:$E$27)
Notice that I made the cell references absolute? Again, lazy. I want to be able to write this formula once and copy down.
So, why would I not do it that way?
This is a personal choice thing, but I tend to try to give meaningful names to ranges of data I am manipulating so that I can think about what data I am trying to pull rather than being bogged down in making sure cell references match exactly. (Great at math, suck at arithmetic, what can I say?)
Tables are not the only way to do this. Stay tuned next week, where we’ll talk about Named Ranges and how to use them.
Please feel free to contact me with any questions you may have!