Excel Formula: Double (And More) Conditional Sums
Let's say you have an excel spreadsheet for guys that sell billboard space with 3 columns: Seller, Billboard Location, and number of days. Let's say you wanted to find out how many days John sold a certain billboard for. Excel doesn't have an elegant way built in for double-conditional sums. There's a plugin you can install, but the formula is UGLY, and really doesn't work past 2 variables. If you wanted to do a triple-conditional sum, you're basically out of luck.
The solution I've come up with uses 3 features:
- SUMIF: SUMIF is a conditional sum formula based on a single variable. It takes 3 arguments: The range of cells to check against, the value you're searching for, and the corresponding range of cells to add if the first cell meets the conditions. Read about it here.
- CONCATENATE: This function just combines text into one big text. If A2="Joe" and B2="South St." then CONCATENATE(A2,B2)="JoeSouth St."
- Filter Uniques: Excel can take a list of items and separate it out into JUST the unique entries; this will be critical to pare down the unnecessary data. Select your range, go to the Data menu, then advanced filter, then choose your range (just the Unique ID column) and check the box for "Unique Records Only." This feature doesn't work on formulas; what you must to is select your whole column with the formula in it, copy it, then instead of pasting it in the same place chose "paste special" and select values...this just leaves the formula's result in place.
First, we need to take all of our indexes and concatenate them, so that we have a unique field for each possible combination. This works for any number of indexes. In this case, like I showed above, we're concatenating the name and location. Then, you can run the SUMIF command with the unique column we created being the range to check. Let me create an example below:
Rep | Board | Days Sold | Unique ID | SUM |
Joe | One | 5 | =CONCATENATE(A2,B2) | =SUMIF(D:D,D2,C:C) |
Joe | One | 10 | =CONCATENATE(A3,B3) | =SUMIF(D:D,D3,C:C) |
Joe | One | 12 | =CONCATENATE(A4,B4) | =SUMIF(D:D,D4,C:C) |
Joe | Three | 6 | =CONCATENATE(A5,B5) | =SUMIF(D:D,D5,C:C) |
Chris | Two | 8 | =CONCATENATE(A6,B6) | =SUMIF(D:D,D6,C:C) |
Chris | One | 9 | =CONCATENATE(A7,B7) | =SUMIF(D:D,D7,C:C) |
Dave | One | 4 | =CONCATENATE(A8,B8) | =SUMIF(D:D,D8,C:C) |
Dave | Two | 2 | =CONCATENATE(A9,B9) | =SUMIF(D:D,D9,C:C) |
Dave | Two | 7 | =CONCATENATE(A10,B10) | =SUMIF(D:D,D10,C:C) |
This produces a table like this:
Rep | Board | Days Sold | Unique ID | SUM |
Joe | One | 5 | JoeOne | 27 |
Joe | One | 10 | JoeOne | 27 |
Joe | One | 12 | JoeOne | 27 |
Joe | Three | 6 | JoeThree | 6 |
Chris | Two | 8 | ChrisTwo | 8 |
Chris | One | 9 | ChrisOne | 9 |
Dave | One | 4 | DaveOne | 4 |
Dave | Two | 2 | DaveTwo | 9 |
Dave | Two | 7 | DaveTwo | 9 |
which you can then use the "Filter Uniques" function on the Unique ID column to pare down to this:
Rep | Board | Days Sold | Unique ID | SUM |
Joe | One | 5 | JoeOne | 27 |
Joe | Three | 6 | JoeThree | 6 |
Chris | Two | 8 | ChrisTwo | 8 |
Chris | One | 9 | ChrisOne | 9 |
Dave | One | 4 | DaveOne | 4 |
Dave | Two | 2 | DaveTwo | 9 |
So, finally, once we remove the unnecessary columns and re-title the result column:
Rep | Board | Days Sold Per User, Per Board |
Joe | One | 27 |
Joe | Three | 6 |
Chris | Two | 8 |
Chris | One | 9 |
Dave | One | 4 |
Dave | Two | 9 |