简体   繁体   中英

Excel complicated count function

I have kind of a complicated count I can't seem to figure out. Basically I have a table that looks similar to this image:

样本数据

Now what I need to do is:

  1. Tally the number of 1's if the category = "Anon" in one cell, then count the number of 2's and 3's in separate cells all if the category = "Anon".
  2. Wash/Rinse/Repeat for if it's "Watterson" and "Davis".

Is there any way I can count the occurrences of 1|2|3 and have it separated by category like this?

Sorry, kind of an Excel noob here. I didn't think pivot tables would be correct though (especially because they want the dates to be columns, plus I couldn't figure out how to insert a conditional). Any pointers in the right direction would be appreciated.

Let's suppose that your screenshot shows cells A1:I6.

Then ...

  • Add column headings "1", "2", "3" in cells J1:L1
  • Put the formula =COUNTIF($C2:$I2,J$1) into J2 and copy it across and down
  • Set up a list of unique Categories (Anon, Watterson etc) starting in A10
  • Add headings in row 9 like "Category", "Tally of 1s", "Tally of 2s", "Tally of 3s"
  • Put the formula =SUMIF($B$2:$B$6,$A10,J$2:J$6) into B10 and copy it across and down

My guess is that someone cleverer than I could construct a sumproduct formula for B10 that works without the need for the helper columns J:L.

[Edit] Using Maki's sumproduct formula in my structure, you can scrap helper values in cols J:I and put this into B10 -- =SUMPRODUCT(($B$2:$B$6=$A10)*($C$2:$I$6=B$9))

assuming that you start from cell A1,

=SUMPRODUCT((list name to search for)*(value to search in the data area))

=SUMPRODUCT(($B$2:$B$6="Anon")*($C$2:$I$6=1))
=SUMPRODUCT(($B$2:$B$6="Anon")*($C$2:$I$6=2))

...

=SUMPRODUCT(($B$2:$B$6="Watterson")*($C$2:$I$6=1))

...etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM