Counif function

ryan8200

Active Member
Joined
Aug 21, 2011
Messages
357
How to calculate the total fruits consumed by 3 students within 5 days ? Please take note each student can consume more than 1 per day ?

Student 1
Student 2
Student 3
Day 1
apple / kiwi
orange
apple
Day 2
orange
honey dew
apple / kiwi
Day 3
kiwi
apple
orange
Day 4
honey dew / kiwi
kiwi
kiwi
Day 5
apple
kiwi
apple

<tbody>
</tbody>


Final Output


Apple : 6
Kiwi : 7
Orange : 3
Honey Dew: 2
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi,

Assuming your source table is in the range A1:D6 (including the column and row labels, as you give), and that your results table is in F1:G4, enter this formula in G1 and copy down as required:

=SUMPRODUCT(--(ISNUMBER(SEARCH(F1,$B$2:$D$6))))

Regards
 
Upvote 0
Hi,

Assuming your source table is in the range A1:D6 (including the column and row labels, as you give), and that your results table is in F1:G4, enter this formula in G1 and copy down as required:

=SUMPRODUCT(--(ISNUMBER(SEARCH(F1,$B$2:$D$6))))

Regards

Thanks for your effort. But what will happen if another fruit also has similar string such as: XXXA & XX. Will the formula still workable with accurate output ?
 
Upvote 0
Will you potentially have the same fruit consumed twice/more times by the same person on the same day so the data would look like:


Day 1______apple/kiwi/apple
 
Upvote 0
Sorry. Not sure I follow. What do you mean by "similar string such as: XXXA & XX"? Can you give a concrete example involving fruit names, as in your original post?

Regards
 
Upvote 0
Sorry. Not sure I follow. What do you mean by "similar string such as: XXXA & XX"? Can you give a concrete example involving fruit names, as in your original post?

Regards

Let say I want to calculate separately for GRAPE & GRAPEFRUIT , will the formula still workable ?
 
Upvote 0
You could amend that formula to:

=SUMPRODUCT(--ISNUMBER(SEARCH("/"&F1&"/","/"&$B$2:$D$6&"/")))

But my query above is still relevant
 
Upvote 0
=countif($j$3:$l$10,i12)

=countif(range,(cell for the name of the fruit)

try this..

The one sent by xor lx ​is also correct..
 
Upvote 0
Hi Ryan,

Let say I want to calculate separately for GRAPE & GRAPEFRUIT , will the formula still workable ?

Yes that is the case because if you have GRAPE and GRAPEFRUIT then the results will be:

GRAPE - 2
GRAPEFRUIT - 1

So any idea how we go around this?
 
Upvote 0
Maybe this:

Layout

Student 1
Student 2
Student 3
Day 1
apple / kiwi
orange
apple
Day 2
orange / myapple
honey dew
apple / kiwi
Day 3
kiwi / kiwi
apple
orange
Day 4
honey dew/kiwi
kiwi
kiwi
Day 5
apple
kiwi
apple
*
Final Output
Without repetition
With repetition
Apple
6
6
Kiwi
7
8
Orange
3
3
Honey Dew
2
2
************
*********************
***************
***********

<tbody>
</tbody>


Formulas

Code:
In B9 enter this formula

=SUMPRODUCT(--ISNUMBER(SEARCH(" "&A9&" /"," "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")))

In C9 enter this formula

=SUMPRODUCT(
(LEN(" "&TRIM(SUBSTITUTE($B$2:$D$6,"/"," / "))&" /")-LEN(SUBSTITUTE(" "&UPPER(TRIM(SUBSTITUTE($B$2:$D$6,"/"," / ")))&" /"," "&UPPER($A9)&" /","")))/
LEN(" "&$A9&" /"))


Markmzz
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top