Reputation: 7269
I have an Excel spreadsheet with a table of data in it. The columns are "Item", "Price", "Owned". I want to sum the price of the owned items. In SQL, I would simply do
select sum(price) from table where owned="y"
Is there a formula I can use to do something similar in Excel? The DSUM function seems to do something like what I want, but I can't understand how the criteria work.
More generally, this is a problem I encounter a lot. I use SQL for a lot of data analysis, and use aggregate functions frequently. And yet, if I have my data in a spreadsheet rather than in a database table, I find it extremely difficult to do this type of analysis (without needing to clutter my spreadsheet with masses of working areas). Basically, I need to be able to take the sum/count/max/min/etc of a column, only including rows satisfying a particular condition, without needing a work column for each condition (it's easy enough with a work column, just have a column containing IF(condition,column,0) and then sum/count/whatever it).
Thanks, Paul.
Upvotes: 1
Views: 3302
Reputation: 3683
You can use SUMIF
or use array formulas. I prefer the latter method myself. As an example, say you have the Item, Price, and Owned data in columns A, B, and C, respectively. Then your array formula would look something like SUM(B:B*(C:C="y"))
. Enter it using Ctrl+Shift+Enter as you would for an array formula and you are good. Of course, you can use Excel's other aggregation functions with minor tweaks, too.
Upvotes: 4
Reputation: 309028
Filtering data and applying functions to the result is the closest thing I can think of.
Upvotes: 0