Count unique instances of text between two dates

B5rocksass

Board Regular
Joined
Jan 10, 2017
Messages
56
Office Version
  1. 2016
Platform
  1. Windows
Please note that my skills are few and far between. I have tried the following formula with CTRL+SHIFT+ENTER but it returns zero. I need to find the unique # of customers that purchased material each month. Here is the formula that failed: =SUMPRODUCT(IF((Date<h15)*(date>=H14),1/COUNTIFS(Customer_Name,"<="&H15,Date,">="&H14,Customer_Name,Customer_Name),0))

I would like to put this in a table that shows the calendar year, Jan-16 to Jan -17. So it looks like:

DATE
# OF CUSTOMERS
JAN-16
3
FEB-16
2
MAR-16
2

<tbody>
</tbody>


Starting from a table that looks similar to this:

DATE
CUSTOMER NAME
JAN-16
CUSTOMER_NAME_01
JAN-16
CUSTOMER_NAME_01
JAN-16
CUSTOMER_NAME_02
JAN-16
CUSTOMER_NAME_03
FEB-16
CUSTOMER_NAME_01
FEB-16
CUSTOMER_NAME_02
FEB-16
CUSTOMER_NAME_02
MAR-16
CUSTOMER_NAME_01
MAR-16
CUSTOMER_NAME_01
MAR-16
CUSTOMER_NAME_03
MAR-16
CUSTOMER_NAME_03

<tbody>
</tbody>
</h15)*(date>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Using a formula provided by Exceljet, you can do the following:


AB
1DATECUSTOMER COUNT
2JAN-163
3FEB-162
4MAR-162
5
6DATECUSTOMER_NAME
7JAN-16CUSTOMER_NAME_01
8JAN-16CUSTOMER_NAME_01
9JAN-16CUSTOMER_NAME_02
10JAN-16CUSTOMER_NAME_03
11FEB-16CUSTOMER_NAME_01
12FEB-16CUSTOMER_NAME_02
13FEB-16CUSTOMER_NAME_02
14MAR-16CUSTOMER_NAME_01
15MAR-16CUSTOMER_NAME_01
16MAR-16CUSTOMER_NAME_03
17MAR-16CUSTOMER_NAME_03

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


Array Formulas
CellFormula
B2{=SUM(IF(FREQUENCY(IF(BigTable[DATE]=[@DATE], MATCH(BigTable[CUSTOMER_NAME],BigTable[CUSTOMER_NAME],0)),ROW(BigTable[CUSTOMER_NAME])-ROW(BigTable[[#Headers],[CUSTOMER_NAME]])),1))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}. Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
Hi FranzV,

In the formula you have above, I see two questionable bits of data: BigTable and #Headers. I assumed BigTable is the columns of the longer version of the list above, so I used A:B and for # headers in either the first table or the resulting data compilation table I used 2. Then I made it an array, but I got an error. When I hit ok, the first instance of B[DATE] was highlighted in the formula string. Am I doing something wrong?

{=SUM(IF(FREQUENCY(IF(A:B[DATE]=[@DATE], MATCH(A:B[CUSTOMER_NAME],A:B[CUSTOMER_NAME],0)),ROW(A:B[CUSTOMER_NAME])-ROW(A:B[[2],[CUSTOMER_NAME]])),1))}
 
Upvote 0
For the dummy table I created I applied Excel's built-in Table Formatting by selecting a cell within the table and pressing CTRL+T. This makes formulas much easier to read. I encourage you to try it. That said, I have changed the references to normal A1 Style in the formula below. I hope the colors make it easier to understand.


Array Formulas
CellFormula
B2{=SUM(IF(FREQUENCY(IF($A$7:$A:$17=$A2, MATCH($B$7:$B$17,$B$7:$B$17,0)),ROW($B$7:$B$17)-ROW($B$6)),1))}

<tbody>
</tbody>

<tbody>
</tbody>

AB
1DATECUSTOMER COUNT
2JAN-163
3FEB-162
4MAR-162
5
6DATECUSTOMER_NAME
7JAN-16CUSTOMER_NAME_01
8JAN-16CUSTOMER_NAME_01
9JAN-16CUSTOMER_NAME_02
10JAN-16CUSTOMER_NAME_02
11FEB-16CUSTOMER_NAME_01
12FEB-16CUSTOMER_NAME_02
13FEB-16CUSTOMER_NAME_02
14MAR-16CUSTOMER_NAME_01
15MAR-16CUSTOMER_NAME_01
16MAR-16CUSTOMER_NAME_03
17MAR-16CUSTOMER_NAME_03

<tbody>
</tbody>
 
Last edited:
Upvote 0
Running into a problem because the actual document is almost 6,000 rows long and is expected to get longer as we go through the year. When I tried to input the formula as you've described, I got a different error saying "Excel ran out of resources while attempting to calculate one or more formulas. As a result, these formulas cannot be evaluated."

So I copied the table to a different document and deleted all but 200 rows. Got the same error. I updated the formula to include the entire column because it is expected to grow
=SUM(IF(FREQUENCY(IF(A:A=G2,MATCH(B:B,0)),ROW(B:B)-ROW($B$2)),1))
 
Upvote 0
So I copied the table to a different document and deleted all but 200 rows. Got the same error. I updated the formula to include the entire column because it is expected to grow
=SUM(IF(FREQUENCY(IF(A:A=G2,MATCH(B:B,0)),ROW(B:B)-ROW($B$2)),1))

By using references to entire columns you are forcing Excel to do millions of unnecessary calculations. Try using CTRL+T on any cell of your 6,000 row table and using structured references. Any new rows added at the bottom of the table will be included in the calculations automatically.
 
Upvote 0
This document is meant to go to someone that knows even less than I do. She won't know how to run this formula every time. Is there another way that doesn't require having to update the formula each time the report is required?
 
Upvote 0
Row\Col
A​
B​
C​
D​
E​
1​
DATE CUSTOMER NAME DATE # OF CUSTOMERS
2​
Jan-16 CUSTOMER_NAME_01 Jan-16 3
3​
Jan-16 CUSTOMER_NAME_01 Feb-16 2
4​
Jan-16 CUSTOMER_NAME_02 Mar-16 2
5​
Jan-16 CUSTOMER_NAME_03
6​
Feb-16 CUSTOMER_NAME_01
7​
Feb-16 CUSTOMER_NAME_02
8​
Feb-16 CUSTOMER_NAME_02
9​
Mar-16 CUSTOMER_NAME_01
10​
Mar-16 CUSTOMER_NAME_01
11​
Mar-16 CUSTOMER_NAME_03
12​
Mar-16 CUSTOMER_NAME_03

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

=IF($D2="","",SUM(IF(FREQUENCY(IF(1-($B$2:$B$12=""),IF($A$2:$A$12=$D2,MATCH($B$2:$B$12,$B$2:$B$12,0))),ROW($B$2:$B$12)-ROW($B$2)+1),1)))
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,696
Members
449,464
Latest member
againofsoul

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