Reputation: 133
I am attempting to count the number of unique occurrences of an order number between a given date range, which i have successfully achieved using the code below ;
Column A = Date
Column B = Order Number
Cell W3 = From Date
Cell X3 = To Date
{=SUMPRODUCT(IF((A$2:A$10000<=X3)*(A$2:A$10000>=W3),
1/COUNTIFS(A$2:A$10000, "<="&X3,A$2:A$10000, ">="&W3,
B$2:B$10000,B$2:B$10000), 0))}
My issue is that i want to add another crietria which is held in Column U, that value being 'F' for arguments sake. I have tried to break this formula into bite size chunks to understand exactly what it is doing, but it is beyond me.
As you can see from the screen shot, there are 7 unique order numbers between the date range shown in Cell W3 to Cell X3 the result showing in Cell Y3 as per my formula.
I wish to add another formula that counts the same dataset with any row that has the value of 'F' in column U the result would be 1 as per cell Z3 highlighted in red, which i have manually entered.
Can anyone advise please.
Upvotes: 0
Views: 461
Reputation: 3277
Here is another approach using methods from this article: Count unique values among duplicates
Suppose you have the following named ranges:
Use the following formula to return the unique count of order number in the given date range and criteria F:
=SUMPRODUCT(--(FREQUENCY(OrderList*(DateList>=FromD)*(DateList<=ToD)*(Col_U="F"),OrderList*(DateList>=FromD)*(DateList<=ToD)*(Col_U="F"))>0))-1
The difficult part is to understand the methodology of finding the filtered range using this equation
=OrderList*(DateList>=FromD)*(DateList<=ToD)*(Col_U="F")
.then use
FREQUENCY(filtered_range,filtered_range)>0
to find out how many order numbers have more than one appearance in the filtered range, and lastly use SUMPRODUCT to return the total count. The-1
at the end of my formula is to taken out the count of duplicated0
returned in the filtered range.
Let me know if you have any questions. Cheers :)
Upvotes: 1
Reputation: 162
Formula in cell H3:
=SUMPRODUCT(IF((A$2:A$10000<=F3)*(A$2:A$10000>=E3)*(C$2:C$10000=G3),
1/COUNTIFS(A$2:A$10000,"<="&F3,A$2:A$10000,">="&E3,C$2:C$10000,"="&G3,
B$2:B$10000,B$2:B$10000), 0))
Upvotes: 2