Count If with multiple criteria and unique values

dixon1983

Board Regular
Joined
Apr 23, 2005
Messages
175
Hi,
I dont know if this is possible or not but thought I'd ask anyway.

I have a sheet of data and want to run a count on the values in Column A with the following criteria:

- If the value in column B is repeated then the value in column A can only be counted once...
- Column C must equal 'M'.


Example:
A.....B.....C
1.....42....M
1.....42....M
2.....41....A
2.....41....M
1.....56....M


In this example 1 would be counted 2 times, and 2 would be counted once.

I have about 15 sheets of data like this and would like a master sheet to look into each sheet and give me a count of each so id prefer to not use the advanced filter => unique variables option if possible.

Any help would be greatly appreciated.

Dixon.
 
The method that evolved in this thread is amazing. May I bump the thread with a question though?

My personalised formula works ok until I add the wildcard in the last IF - $F5&"*". During trial and error, replacing that with $F5 and adjusting F5 to a precise value, it works. Any ideas??
Code:
=SUM(IF(FREQUENCY(
IF(1-(Export!$B2:$B40000=""),
IF(Export!$M2:$M40000>=G$2,
IF(Export!$M2:$M40000<=J$2,
IF(Export!$D2:$D40000=$B5,
IF(Export!$F2:$F40000=$D5,
[B]IF(Export!$K2:$K40000=$F5&"*"[/B],
MATCH(Export!B2:B40000,Export!B2:B40000,0))))))),ROW(Export!B2:B40000)-ROW(Export!B2)+1),1))

Control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(
      IF(1-(Export!$B$2:$B$40000=""),
      IF(Export!$M$2:$M$40000>=G$2,
      IF(Export!$M$2:$M$40000<=J$2,
      IF(Export!$D$2:$D$40000=$B5,
      IF(Export!$F$2:$F$40000=$D5,
      IF(ISNUMBER(SEARCH("|"&$F5,"|"&Export!$K2:$K40000)),
      MATCH(Export!$B$2:$B$40000,Export!$B$2:$B$40000,0))))))),
       ROW(Export!$B$2:$B$40000)-ROW(Export!$B$2)+1),1))

Hope the speed of performance will be bearable.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Holy crap, what's that "|" sorcery? Can you please explain what's happening? :)

Searching for say da in a range consisting of

daque
ada
nada

where we only want to pick out daque, not ada or nada, we can better search:

|da

in:

|daque
|ada
|nada

It works, but I'll only know if it's bearable when the report extends to it's ultimate size. Which will be soon.

You might then want to consider other means like SQL for example.
 
Upvote 0
Hi,
Recently I ran into a problem where I unable to get the formula right. Need a helping hand.

I have following data

ABC
Ticket noDateAmount
TT-00003081768112/30/201660
TT-00003081768112/30/201660
TT-00003081768112/30/201660
TT-00003081946412/30/201624
TT-00003082652012/31/201693
TT-00003082652012/31/201677
TT-00003081981112/30/201645
TT-00003082731012/31/2016104
TT-00003081134612/31/201681
TT-00003082652112/31/201615
TT-00003082652112/31/201613
TT-00003082652112/31/201617
TT-00003082652112/31/201629
TT-00003082652112/31/201692
TT-00003082652112/31/201672

<colgroup><col><col><col></colgroup><tbody>
</tbody>

What I need is Max Value of Amount of Each unique ticket aggregated on date.

Something like this:

DateTotal Amount
12/31/2016370
12/30/2016129

<colgroup><col span="2"></colgroup><tbody>
</tbody>


The working of the above result would be based on:
Ticket no Max of AmountDate
TT-000030811346 8112/31/2016
TT-000030817681 6012/30/2016
TT-000030819464 2412/30/2016
TT-000030819811 4512/30/2016
TT-000030826520 9312/31/2016
TT-000030826521 9212/31/2016
TT-000030827310 10412/31/2016


<colgroup><col span="3"></colgroup><tbody>
</tbody>
 
Upvote 0
@djawaz

Row\Col
A​
B​
C​
D​
E​
F​
1​
Ticket noDateAmountDateTotal Amount
2​
TT-000030817681
12/30/2016
60
12/31/2016
370
3​
TT-000030817681
12/30/2016
60
12/30/2016
129
4​
TT-000030817681
12/30/2016
60
5​
TT-000030819464
12/30/2016
24
6​
TT-000030826520
12/31/2016
93
7​
TT-000030826520
12/31/2016
77
8​
TT-000030819811
12/30/2016
45
9​
TT-000030827310
12/31/2016
104
10​
TT-000030811346
12/31/2016
81
11​
TT-000030826521
12/31/2016
15
12​
TT-000030826521
12/31/2016
13
13​
TT-000030826521
12/31/2016
17
14​
TT-000030826521
12/31/2016
29
15​
TT-000030826521
12/31/2016
92
16​
TT-000030826521
12/31/2016
72

A2:A16 is named as Ticket in Name Manager; B2:B16 as Date, and C2:C16 as Amount.

Define also Ivec in Name Manager as referring to:

=ROW(Ticket)-ROW(INDEX(Ticket,1,1))+1

In F2 control+shift+enter, not just enter, and copy down:

=SUM(MAXIFS(Amount,Ticket,IF(FREQUENCY(IF(1-(Ticket=""),IF(Date=E2,MATCH(Ticket,Ticket,0))),Ivec),Ticket),Date,E2))

MAXIFS requires at least a 2016 Excel version.
 
Upvote 0
@djawaz

Row\Col
A​
B​
C​
D​
E​
F​
1​
Ticket noDateAmountDateTotal Amount
2​
TT-000030817681
12/30/2016
60
12/31/2016
370
3​
TT-000030817681
12/30/2016
60
12/30/2016
129
4​
TT-000030817681
12/30/2016
60
5​
TT-000030819464
12/30/2016
24
6​
TT-000030826520
12/31/2016
93
7​
TT-000030826520
12/31/2016
77
8​
TT-000030819811
12/30/2016
45
9​
TT-000030827310
12/31/2016
104
10​
TT-000030811346
12/31/2016
81
11​
TT-000030826521
12/31/2016
15
12​
TT-000030826521
12/31/2016
13
13​
TT-000030826521
12/31/2016
17
14​
TT-000030826521
12/31/2016
29
15​
TT-000030826521
12/31/2016
92
16​
TT-000030826521
12/31/2016
72

<tbody>
</tbody>


A2:A16 is named as Ticket in Name Manager; B2:B16 as Date, and C2:C16 as Amount.

Define also Ivec in Name Manager as referring to:

=ROW(Ticket)-ROW(INDEX(Ticket,1,1))+1

In F2 control+shift+enter, not just enter, and copy down:

=SUM(MAXIFS(Amount,Ticket,IF(FREQUENCY(IF(1-(Ticket=""),IF(Date=E2,MATCH(Ticket,Ticket,0))),Ivec),Ticket),Date,E2))

MAXIFS requires at least a 2016 Excel version.


Thank you Aladin. Your input was indeed quite helpful.
So here is the formula which can work in Excel 2013:

=SUM(IF(Date=E2,(MATCH(Ticket,IF(COUNTIFS(Ticket,Ticket,Amount,">"&Amount,Date,E2)=0,Ticket),0)=ROW(Ticket)-MIN(ROW(Ticket))+1)*Amount))
 
Upvote 0
Thank you Aladin. Your input was indeed quite helpful.
So here is the formula which can work in Excel 2013:

=SUM(IF(Date=E2,(MATCH(Ticket,IF(COUNTIFS(Ticket,Ticket,Amount,">"&Amount,Date,E2)=0,Ticket),0)=ROW(Ticket)-MIN(ROW(Ticket))+1)*Amount))

You are welcome. You could have used Ivec too:

{=SUM(IF(Date=E2,IF(MATCH(Ticket,IF(COUNTIFS(Ticket,Ticket,Amount,">"&Amount,Date,E2)=0,Ticket),0)=Ivec,Amount)))}
 
Upvote 0
Hi - I tried figuring my problem, very similar to this thread,hoping someone can help out.

Please look table below:

Column
A B C D E F

BOLAS R FANN20/01/201608/02/201638.22Division 1
BOLAS R FANN20/01/201608/02/201657.33Division 1
BOLAS R FANN09/08/201609/08/20167.35Division 1
CCLES LPER27/05/201627/05/20167.35Division 1
CCLES LANN22/01/201627/01/201622.05Division 1
CCLES LANN01/03/201601/03/20167.35Division 1
CCLES LANN15/03/201618/03/201629.40Division 1
CCLES LPER29/01/201629/01/20167.35Division 1
CCLES LPER17/02/201617/02/20167.35Division 1
CCLES LPER31/03/201601/04/201614.70Division 1
KORD R AANN08/08/201619/08/201618.38Division 1
KORD R AANN08/08/201619/08/201655.13Division 1
KORD R AANN13/12/201614/12/201614.70Division 1
KORD R APER09/09/201609/09/20167.35Division 1
KORD R APER30/11/201601/12/20167.35Division 2
KORD R APER30/11/201601/12/20167.35Division 2
KORD R APER05/12/201606/12/201614.70Division 2
KORD R APER15/04/201615/04/20167.35Division 2
BOLAS R FANN14/06/201614/06/20167.35Division 2
ECCLES J LANN30/05/201630/05/20167.35Division 2
ECCLES J LPER05/05/201606/05/201614.70Division 2
FORD R AANN15/12/201616/12/201614.70Division 3
FORD R AANN03/01/201713/01/201754.12Division 3
FORD R AANN03/01/201713/01/201712.03Division 3
FORD R APER25/02/201626/02/201614.70Division 3
BINK P HPER05/12/201605/12/20167.35Division 3
SUTT MPER22/02/201626/02/201622.05Division 3
SUTT MPER22/02/201626/02/201614.70Division 3
SUTT MPER02/03/201602/03/20167.35Division 3
SUTT MPER16/03/201616/03/20167.35Division 3
SUTT MPER23/03/201623/03/20167.35Division 4
SUTT MPER13/04/201613/04/20167.35Division 4
SUTT MPER20/04/201620/04/20167.35Division 4
SUTT MPER04/05/201604/05/20167.35Division 4
SUTT MPER16/05/201616/05/20167.35Division 4
SUTT MPER23/05/201623/05/20167.35Division 4
SON MANN29/03/201611/04/201637.80Division 4
SON MANN29/03/201611/04/201621.00Division 4
SON MANN12/04/201620/04/201644.40Division 4
SON MANN21/04/201621/04/20166.90Division 4
SON MPER04/01/201604/01/20167.50Division 4
VIAN RANN12/07/201618/07/201610.50Division 4
VIAN RANN12/07/201618/07/201626.25Division 4
VIAN RPER05/07/201606/07/201614.70Division 4
VIAN RANN13/05/201613/05/20162.85Division 4
VIAN RPER04/02/201604/02/20167.35Division 4
VIAN RPER01/03/201601/03/20162.85Division 4
VIAN RPER11/05/201611/05/20161.50Division 4
VIAN RPER02/06/201603/06/201614.70Division 4

<tbody>
</tbody>

What I'm trying to count is: the average number of hrs (Column E) for specific type of leave (ANN or PER), between range of dates , for particular division, and total average for whole divisions.
Hope it's clear.
Thanks for your help.
 
Upvote 0
[...]
What I'm trying to count is: the average number of hrs (Column E) for specific type of leave (ANN or PER), between range of dates , for particular division, and total average for whole divisions.
[...]

Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
1​
2​
BOLAS R F ANN
1/20/2016
2/8/2016
38.22
Division 1ANN
3​
BOLAS R F ANN
1/20/2016
2/8/2016
57.33
Division 1PER
4​
BOLAS R F ANN
8/9/2016
8/9/2016
7.35
Division 1
1/20/2016​
5​
CCLES L PER
5/27/2016
5/27/2016
7.35
Division 1
3/1/2016​
6​
CCLES L ANN
1/22/2016
1/27/2016
22.05
Division 1division 1
7​
CCLES L ANN
3/1/2016
3/1/2016
7.35
Division 1
23.275​
8​
CCLES L ANN
3/15/2016
3/18/2016
29.4
Division 1
9​
CCLES L PER
1/29/2016
1/29/2016
7.35
Division 1
10​
CCLES L PER
2/17/2016
2/17/2016
7.35
Division 1
11​
CCLES L PER
3/31/2016
4/1/2016
14.7
Division 1

In H7 control+shift+enter, not just enter:

=AVERAGE(IF(ISNUMBER(MATCH($B$2:$B$50,$H$2:$H$3,0)),IF($C$2:$C$50>=H4,IF($D$2:$D$50<=H5,IF($F$2:$F$50=H6,$E$2:$E$50)))))

This is a multiconditional average of hours where one of the conditions is "division 1", a particular division. Care to clarify what you mean by "total average for whole divisions"?
 
Upvote 0

Forum statistics

Threads
1,215,482
Messages
6,125,060
Members
449,206
Latest member
Healthydogs

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