Returning a count/sum based on mulitple criteria

AliG999

New Member
Joined
Nov 6, 2017
Messages
20
First time poster

I hope you can help. I have data which is broken down per year for which I need to return a count against each unique ID but in which there may be multiple rows linked to that ID but I would like a unique count and in some cases a sum of and want to avoid duplicate counts. the data looks something like below:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Year[/TD]
[TD]Unique ID[/TD]
[TD]Case No.[/TD]
[TD]Gender[/TD]
[TD]No. of Sales[/TD]
[TD]Total No. of Cases per unique ID[/TD]
[/TR]
[TR]
[TD]2012[/TD]
[TD]E542[/TD]
[TD]123[/TD]
[TD]Female[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2012[/TD]
[TD]E542[/TD]
[TD]589[/TD]
[TD]Male[/TD]
[TD]1[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2012[/TD]
[TD]E542[/TD]
[TD]123[/TD]
[TD]Female[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2013[/TD]
[TD]E588[/TD]
[TD]235[/TD]
[TD]Male[/TD]
[TD]3[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2013[/TD]
[TD]E588[/TD]
[TD]415[/TD]
[TD]Male[/TD]
[TD]1[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2013[/TD]
[TD]E588[/TD]
[TD]256[/TD]
[TD]Female[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]


For e.g. I would like to count for 2012 how many females/males per unique ID (to avoid duplication in counting the same individuals more than once)

Or I may wish to sum how many sales per unique ID for each year.

I have tried all sorts of COUNT IF/S or SUM/IFs variations but cannot figure it out - any help would be gratefully appreciated.

thanks

Ali
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
First time poster

I hope you can help. I have data which is broken down per year for which I need to return a count against each unique ID but in which there may be multiple rows linked to that ID but I would like a unique count and in some cases a sum of and want to avoid duplicate counts. the data looks something like below:

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Year[/TD]
[TD]Unique ID[/TD]
[TD]Case No.[/TD]
[TD]Gender[/TD]
[TD]No. of Sales[/TD]
[TD]Total No. of Cases per unique ID[/TD]
[/TR]
[TR]
[TD]2012[/TD]
[TD]E542[/TD]
[TD]123[/TD]
[TD]Female[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2012[/TD]
[TD]E542[/TD]
[TD]589[/TD]
[TD]Male[/TD]
[TD]1[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2012[/TD]
[TD]E542[/TD]
[TD]123[/TD]
[TD]Female[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2013[/TD]
[TD]E588[/TD]
[TD]235[/TD]
[TD]Male[/TD]
[TD]3[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2013[/TD]
[TD]E588[/TD]
[TD]415[/TD]
[TD]Male[/TD]
[TD]1[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]2013[/TD]
[TD]E588[/TD]
[TD]256[/TD]
[TD]Female[/TD]
[TD]2[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]


For e.g. I would like to count for 2012 how many females/males per unique ID (to avoid duplication in counting the same individuals more than once)

Or I may wish to sum how many sales per unique ID for each year.

I have tried all sorts of COUNT IF/S or SUM/IFs variations but cannot figure it out - any help would be gratefully appreciated.

thanks

Ali

Assuming the Columns ranges are from A to F

=SUMPRODUCT(--($A$2:$A$7=2012),--(MATCH($B$2:$B$7&$D$2:$D$7,$B$2:$B$7&$D$2:$D$7,0)=ROW(INDEX($B$2:$B$7,0,0))-ROW($A$2)+1))
 
Upvote 0
Thanks Vane

I've used the formula you suggested on my actual datasheet =SUMPRODUCT(--('TELECOMS REQUESTS'!$A$3:$A24=2012),--(MATCH($B$3:$B$24&$AE$3:$AE$24,$B$3:$B$24&$AE$3:$AE$24,0)=ROW(INDEX($B$3:$B24,0,0))-ROW($A$3)+1))

The only thing is it returns a value of 7 however when I do a check using a pivot table it should be 9 - have I done something wrong?
 
Upvote 0
Apologies Vane

It did work I just forgot to add in the sheet name for the ranges - dafty! Been a long day trying to figure this out. Can I ask for an idiots explanation of the above formula?

Thanks again for all your help

ali
 
Upvote 0

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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