Count Unique based on two/three different criteria

Melimob

Active Member
Joined
Oct 16, 2011
Messages
395
Office Version
  1. 365
Hi There

I have a data set with multiple columns where I need to count the unique fields in a seperate tab based on multiple criteria.

PNRBooking DateBooking AgentMAX Booking Agent ID
AAVBHD0110/09/2018AO99355
AAWTZK0105/09/2018BM86788
ABDYNH0110/09/2018GM23023
ABGRLL0105/09/2018SW25238
ADVQJQ0104/09/2018AO99355
AENSSR0110/09/2018JP14647
AFFGNM0105/09/2018PB28180
AGJTEJ0104/09/2018SD23509
AGJTEJ0104/09/2018SD23509



<tbody>
</tbody>

1 - I want to only take the first 6 characters from PNR column
2 - I want to summarise how many unique times column A (PNR) + column D (MAX ID) appear together
3 - I also want to summarise point 2 plus month of booking date

I can do it by copying to a diff sheet, removing duplicates and then using countif formulas but in case I wanted to just read from the raw data tab without copying/removing, is there any formula I can use?

Many thanks
Melimob
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
What does 1 mean - a listing of the first six items from PNR?

What is the expected value for 2?

Item 3 needs some elaboration what it amounts to.
 
Upvote 0
Hi Aladin

Point 1 means I only want to analyse unique codes based on the first 6 characters (i.e. exclude last 2 digits..01)
Point 2 so for example, this set should say: Max ID 23509 = 1 PNR since Max ID 23509 = 1 PNR since AGJTEJ should only be counted once as unique for this MAXID
Point 3 is: In Sept, Max ID 23509 = 1 PNR since AGJTEJ should only be counted once

Obviously my data has a whole load more where PNRs may appear multiple times for the same MAXID (counted as one) or different MAXID's (counted per MAXID).

Many thanks
What does 1 mean - a listing of the first six items from PNR?

What is the expected value for 2?

Item 3 needs some elaboration what it amounts to.
 
Last edited:
Upvote 0
Hi - thanks all but I found something on internet and works a treat!
=SUM(IF([@[Max ID ]]=Table2[MAX Booking Agent ID], 1/(COUNTIFS(Table2[MAX Booking Agent ID], [@[Max ID ]], Table2[PNR Stripped], Table2[PNR Stripped])),0))

CTRL+SHFT+ENTER

Thank you
 
Upvote 0

Book1
ABCDEFGHI
1PNRBooking DateBooking AgentMAX Booking Agent IDpnr79/1/2018
2AAVBHD019/10/2018AO99355AAVBHD01mba idpnr #pnr #/month
3AAWTZK019/5/2018BM86788AAWTZK011464711
4ABDYNH019/10/2018GM23023ABDYNH012302311
5ABGRLL019/5/2018SW25238ABGRLL012350911
6ADVQJQ019/4/2018AO99355ADVQJQ012523811
7AENSSR019/10/2018JP14647AENSSR012818011
8AFFGNM019/5/2018PB28180AFFGNM018678811
9AGJTEJ019/4/2018SD23509AGJTEJ019935522
10AGJTEJ019/4/2018SD23509
Sheet1


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

=IFERROR(INDEX($A$2:$A$10,SMALL(IF(FREQUENCY(IF($A$2:$A$10<>"",MATCH(LEFT($A$2:$A$10,6),LEFT($A$2:$A$10,6),0)),ROW($A$2:$A$10)-ROW($A$2)+1),ROW($A$2:$A$10)-ROW($A$2)+1),ROWS($1:1))),"")

In G1 control+shift+enter:

=SUM(IF(FREQUENCY(D2:D10,D2:D10),1))

In G3 control+shift+enter and copy down:

=IF(ROWS($1:1)>$G$1,"",MIN(IF(ISNA(MATCH($D$2:$D$10,$G$2:G2,0)),$D$2:$D$10)))

In H3 control+shift+enter and copy down:

=IF($G3="","",SUM(IF(FREQUENCY(IF($D$2:$D$10<>"",IF($D$2:$D$10=$G3,MATCH($A$2:$A$10,$A$2:$A$10,0))),ROW($A$2:$A$10)-ROW($A$2)+1),1)))

In I3 control+shift+enter and copy down:

=IF($G3="","",SUM(IF(FREQUENCY(IF($D$2:$D$10<>"",IF($D$2:$D$10=$G3,IF($B$2:$B$10-DAY($B$2:$B$10)+1=$I$1,MATCH($A$2:$A$10,$A$2:$A$10,0)))),ROW($A$2:$A$10)-ROW($A$2)+1),1)))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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