Can anyone help with complex counting scenario in a HUGE table

Mike03858

New member
Joined
Aug 14, 2017
Messages
4
Reaction score
0
Points
0
Hi there - this is my first post here, though I've been greatly appreciative of the tons of help you've given others in the past that also was a big help to me!

So,I have a table like the one below that's 150k lines of sales contract info - each line item is a one-year contract. I'm trying to figure out the average contract length for each product so I have to get accurate lengths for each contract. The problem is if I try to use COUNTIF for a given customer and product it doesn't work.

As an example below, with Nashop, COUNTIF gives me "7" indicating Nashop has a contract that's lasted 7 years. But there are actually two instances of the same contract at Nashop, one contract started 4/1/12 and went through 3/31/16 (highlighted in yellow), thus 4 years; the other contract started 5/1/12 and ended 4/30/15 (highlighted in blue), thus 3 years.

Customer NameLocationProduct NumberStart DateEnd Date
GPGNashopCVB-2304/01/1203/31/13
GPGNashopCVB-2304/01/1503/31/16
GPGNashopCVB-2304/01/1303/31/14
GPGNashopCVB-2304/01/1403/31/15
GPGNashopCVB-2305/01/1204/30/13
GPGNashopCVB-2305/01/1404/30/15
GPGNashopCVB-2305/01/1304/30/14
GPGWilmotCVB-2312/01/1211/30/13
GPGWilmotCVB-2312/01/1311/30/14
GPGWilmotCVB-2303/15/133/14/14
GPGWilmotCVB-233/15/143/14/15
GPGWilmotCVB-233/15/153/15/16
GPGWilmotCVB-2309/15/1212/14/12
GPGWilmotCVB-2312/15/1103/14/12

The table is organized by customer and product number with start and end dates for each line item (which is a one-year contract period). I just need to be able to count the rows representing different contracts even though the product is the same - and the key to recognizing the same contract is the common annual start dates for contracts that are simply renewed.

Can anyone suggest a macro or array formula or anything that can recognize and count the lines for each different contract? Something that could be applied to the entire table - maybe in a new column? I'd like to do some kind of COUNTIF that would give me a result for Nashop of 4 and 3 rather than 7?

Any advice will be very much appreciated. Thanks - Mike
 
This arrya formula does it, although you might find it a tad slow with that much data

=MAX(IF(($A$2:$A$15=A2)*(TEXT($D$2:$D$15,"ddmm")=TEXT(D2,"ddmm")),YEAR($E$2:$E$15)))-MIN(IF(($A$2:$A$15=A2)*(TEXT($D$2:$D$15,"ddmm")=TEXT(D2,"ddmm")),YEAR($D$2:$D$15)))

It is an array formula, so commit with Ctrl-Shift-Enter
 
Wow - thanks for the fast response! So I copy the formula into a new column then commit?
 
Copy it into a new column on the first row, commit with Ctrl-Shift-Enter, then copy down.
 
Copy it into a new column on the first row, commit with Ctrl-Shift-Enter, then copy down.

Hey Bob - sorry to keep bothering you - the real column IDs are below:


F T I W X
Customer Name Location Product Number Start Date End Date
GPG Nashop CVB-23 04/01/12 03/31/13...

And the rows go from 11 to 600 inclusive.



So I rewrote your formula from:

=MAX(IF(($A$2:$A$15=A2)*(TEXT($D$2:$D$15,"ddmm")=TEXT(D2,"ddmm")),YEAR($E$2:$E$15)))-MIN(IF(($A$2:$A$15=A2)*(TEXT($D$2:$D$15,"ddmm")=TEXT(D2,"ddmm")),YEAR($D$2:$D$15)))

To this:
=MAX(IF(($F$11:$F$600=F11)*(TEXT($W$11:$W$600,"ddmm")=TEXT(W11,"ddmm")),YEAR($X$11:$X$600)))-MIN(IF(($F$11:$F$600=F11)*(TEXT($W$11:$W$600,"ddmm")=TEXT(W11,"ddmm")),YEAR($w$11:$w$600)))

So I copied it into the first row of a new column, then copied it down the whole table, then did the CSE array submittal.

Will get back to you with the result....
 
Last edited:
So I copied it into the first row of a new column, then copied it down the whole table, then did the CSE array submittal.

Will get back to you with the result....

That's not how I said, you do one, CSE, copy down.
 
Oh sorry - I did it the way you said (said it wrong above) and it looks like I'm getting good results. Thanks VERY much for your help!
 
Back
Top