Spreadsheets that do arbitrary cell tags?
September 2, 2007 10:24 AM   Subscribe

Ignorant spreadsheet question: do most (or any) spreadsheets have the ability to tag cells with an arbitrary name or label and then do operations on only the cells with that tag?

I want to write a formula that pulls its data from cells in a range that is not just discontinuous but what you might call shotgun-discontinuous; and to be able to append cells to or remove them from this shotgun-discontinuous range easily. Simple example: say I have a list of purchases for the year, with amounts, arranged sequentially by date from Jan 1 to Dec 30. Some of those purchases were related to, oh, a goat. Whenever I enter a new purchase for goat feed, goat clothing, goat education, goat cosmetics, goat vasectomy, etc. I'd like to tag the amount as "goat" and at the end of the month or year just do =sum(goat). Can I do that?

I'm aware or Excel named cells but it looks as if I can't have more than one cell named "goat" in a given spreadsheet, so that's not the answer. I guess I could also enter the text string "goat" in the cell beside any pertaining-to-goat amount and when write an IF-formula (IF cell next to amount contains string "goat" THEN add amount to running total). But is there a cleaner way to do this? I really do hope to achieve the concision of =sum(goat). Possible? Thanks ever so!
posted by jfuller to Computers & Internet (8 answers total) 2 users marked this as a favorite
 
Best answer: Yep, you want to look into "sumif()". I used exactly this feature for a home budget where I categorized expenses and kept totals by category.

I had one list consisting of line entries in the form of date/desc/cat/amt, and a second list for category subtotals in the form of cat name/subtotal. The "subtotal" cells were where the magic happened, and took the form

=SUMIF(FirstAmountCell:LastAmountCell,CatNameCell,FirstCatCell:LastCatCell)

In my case, it looked like this:
=SUMIF($D$5:$D$200,$G4,$E$5:$E$200).

There's probably an even more elegant way to do it, but this worked for me.

I can send you a copy of my budget worksheet, if you want. Hit me up by e-mail.
posted by adamrice at 11:12 AM on September 2, 2007


I think adamrice has it, but in terms of a "cleaner way" for future spreadsheet construction, I'd suggest using dummy variables for categorical data. So if you have goats and sheep, for which you buy feed and veterinary services, you'd create columns for those four things, and put a "1" in the relevant cells. That way you could do SUMIFs for all goat expenses, all food expenses, all goat food expenses, etc.
posted by Kwantsar at 11:44 AM on September 2, 2007


I'm not sure how having multiple columns for the different categories benefits you. Just use SUMIF with the appropriate criteria.

=sumif(D:D,"goat",E:E)

Or

=sumif(D:D,"food",E:E)
posted by zixyer at 12:12 PM on September 2, 2007


If the cell contains goat food, and you want to look for all mentions of goat, you'll need to

=sumif(D:D,"*food*",E:E)

Which is one reason why dummy variables allow a cleaner construction.
posted by Kwantsar at 12:21 PM on September 2, 2007


erm, replace "*food*" with "*goat*".
posted by Kwantsar at 12:22 PM on September 2, 2007


Or you could just do =sumif(D:D,"goat cosmetics",E:E)+sumif(D:D,"goat food",E:E). But you're right, if the data are more associated with a set of properties rather than neatly partitioned into categories, having a column for each property is better. The most important thing is to first think hard about how you organize your data.
posted by zixyer at 12:32 PM on September 2, 2007


Excel also has a bunch of 'database' functions--DSUM() will do what you want much like SUMIF

Or you might just bite the bullit and start using a database.

But in any case, you really need a category column, as has been mentioned.
posted by hexatron at 1:05 PM on September 2, 2007


Response by poster: Thanks very much to every one who responded, and thanks especially for the pointer to SUMIF. That's what I need.


> The most important thing is to first think hard about how you organize your data.

You mean I can't just jump in and start writing code before I know what it's supposed to do? Darn, what fun is that? (Some may suspect, correctly, that I learned BASIC first and then assembler, neither of which exactly forces an orderly approach to design.)

Actually I believe I want two tags per amount, a coarse one (me, son, daughter, everybody) and a more fine-grained one (food, clothes, gas, etc.) Searching for howto pages with SUMIF examples, I found this page that revealed (to me, anyway) that excel actually has a wizard to help with this sort of thing; and the page also has a lovely precooked example involving exactly two columns of tags.
posted by jfuller at 8:16 PM on September 2, 2007


« Older My employer won't pay us minimum wage, what do I...   |   Will I get paid if I leave today? Newer »
This thread is closed to new comments.