# Count unique values with multiple criteria

#### awalt

##### New Member
I am looking to count something specific, using multiple criteria, however I cannot use the COUNTIF function due to the way my workbooks are linked.

The goal is to count how many unique PARTY ID's fall within a given date range. I thought I had this working using the below formula, but it's not getting all the data. My goal is to count how many rooms I have per date range (unique party ID = room)

{=SUM(--(FREQUENCY(IF((criteria1)*(criteria2),values),values)>0))}

The party ID's should line up directly with the dates listed, however I believe the reason it is not capturing the data is because the PARTY IDs start 2 rows higher than my date ranges on sheet 2. I am not able to change how the sheets are laid out to make the PARTY ID start on the same line, but I can't figure out how to get this to calculate correctly. Below are some screen shots of what my data looks like.

Any help would be appreciated!

=SUM(--(FREQUENCY(IF((Sheet1!A:A="2019-12-12")*(Sheet1!B:B="2019-12-16"),Sheet2!A:A),Sheet2!A:A)>0))

### Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

#### ExcelElliott

##### New Member
Not sure if this will work, but try

= SUM(--(FREQUENCY(IF(Sheet1!A:A = "2019-12-12",IF(Sheet1!B:B = "2019-12-16",Sheet2!A:A)),Sheet2!A:A>0)))

#### ExcelElliott

##### New Member
Also I just noticed that when I did it on my computer I had the dates in other cells, i.e. in your photo maybe put the start date in row 4 and the end date in row 5, and then reference them in the formula

= SUM(--(FREQUENCY(IF(Sheet1!A:A = Sheet2!A4,IF(Sheet1!B:B = Sheet2!A5,Sheet2!A:A)),Sheet2!A:A>0)))

I tried typing in the dates in the formula as you have them and it did not work but did using the modification I mentioned above.

#### awalt

##### New Member
Hi,

So sorry for the late reply! I tried the formula as you suggest above, which is counting the amount of time that date range appears in the list, but not limiting it based on the party ID on sheet 2. I am referencing my dates in sheet 4 as you suggested.

For example the date range 12/11/19 - 12/16/19 the count should be 4 since there are 4 party ID's with that date range, but the formula is returning 14, the # of times that date range appears in the dates sheet on sheet 1.

=SUM(--(FREQUENCY(IF(Sheet1!A:A=Sheet4!A2,IF(Sheet1!B:B=Sheet4!A7,Sheet2!A:A)),Sheet2!A:A>0)))