Mark earliest date in series of sequential dates by criteria

mrpavlos

New Member
Joined
Jul 28, 2018
Messages
23
Hello all. Thank you again for this great forum and the opportunity to learn from the many questions and answers. I have a question, which I hope will make sense. I have been given a reporting task on a daily transaction log where, for example, in Column A of the spreadsheet I will have many SKUs and in Column B I will have a list of dates which will always be in sequence (i.e there will never be any days missing, but the SKUs themselves wont appear on the log every day). My task is to identify in Column C the earliest date in a series of sequential dates for a given SKU. I have given an example below of what I am seeking to do. Once I identify the 'NEW' I then need to work out the most recent date of the occurence of this 'NEW' by SKU (I am thing of a Max/Index formula which I will try out). The formula I have come up with quickly in Column C is also given below but I am wondering if there is a much straightforward way of finding the 'NEW's as there will be roughly in the order of 50K to 100K records over a whole year. Each day another day's worth of transactions is added to the current data. I would love to hear any suggestions using any approach whether formula, VBA, pivottable etc. Thanks again for taking the time to read this and help, Paul

=IF(COUNTIFS($A$2:$A$10,A2,$B$2:$B$10,B2-1)=0,"NEW","")

SKU
ANEW
BNEW
B
A
B
ANEW
B
A
BNEW

<tbody>
[TD="width: 75"]Date[/TD]
[TD="width: 64"][/TD]

[TD="class: xl63, align: right"]01/01/2019 [/TD]

[TD="class: xl63, align: right"]01/01/2019 [/TD]

[TD="class: xl63, align: right"]02/01/2019[/TD]

[TD="class: xl63, align: right"]02/01/2019[/TD]

[TD="class: xl63, align: right"]03/01/2019[/TD]

[TD="class: xl63, align: right"]04/01/2019 [/TD]

[TD="class: xl63, align: right"]04/01/2019[/TD]

[TD="class: xl63, align: right"]05/01/2019[/TD]

[TD="class: xl63, align: right"]06/01/2019 [/TD]

</tbody>
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Maybe a Pivot Table

SKU --> Rows Labels
Date --> Values

Right-click Date field
in Summarize values by pick Max

Hope this helps

M.
 
Upvote 0
Hello M. Thanks so much for taking the time to read and help. Your suggestion of a pivot table would definitely be better than the formula approach given the amount of potential records. However, I need to identify first the 'NEW's so that I can use that in the pivot table filter to work out the most recent occurence of the 'NEW' for each SKU.
 
Upvote 0
Reading more carefully your post I realized that my suggestion does not do what you need. Sorry ...

M.
 
Upvote 0
Thank you again M. I will definitely though use your suggestion re: the pivot table.


I was trying to avoid an auxiliary column (for the sake of performance), but if it seems feasible maybe something like this


[TABLE="class: grid"]
<tbody>[TR]
[TD="bgcolor: #DCE6F1"][/TD]
[TD="bgcolor: #DCE6F1"]
A
[/TD]
[TD="bgcolor: #DCE6F1"]
B
[/TD]
[TD="bgcolor: #DCE6F1"]
C
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
1
[/TD]
[TD]
SKU​
[/TD]
[TD]
Date​
[/TD]
[TD]
Is New​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
2
[/TD]
[TD]
A​
[/TD]
[TD]
01/01/2019​
[/TD]
[TD]
NEW​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
3
[/TD]
[TD]
B​
[/TD]
[TD]
01/01/2019​
[/TD]
[TD]
NEW​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
4
[/TD]
[TD]
B​
[/TD]
[TD]
02/01/2019​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
5
[/TD]
[TD]
A​
[/TD]
[TD]
02/01/2019​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
6
[/TD]
[TD]
B​
[/TD]
[TD]
03/01/2019​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
7
[/TD]
[TD]
A​
[/TD]
[TD]
04/01/2019​
[/TD]
[TD]
NEW​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
8
[/TD]
[TD]
B​
[/TD]
[TD]
04/01/2019​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
9
[/TD]
[TD]
A​
[/TD]
[TD]
05/01/2019​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
10
[/TD]
[TD]
B​
[/TD]
[TD]
06/01/2019​
[/TD]
[TD]
NEW​
[/TD]
[/TR]
</tbody>[/TABLE]


Your formula in column C

Pivot Table (filtered by NEW)

[TABLE="class: grid"]
<tbody>[TR]
[TD="bgcolor: #DCE6F1"][/TD]
[TD="bgcolor: #DCE6F1"]
A
[/TD]
[TD="bgcolor: #DCE6F1"]
B
[/TD]
[TD="bgcolor: #DCE6F1"]
C
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
3
[/TD]
[TD]
SKU​
[/TD]
[TD]
Is New​
[/TD]
[TD]
Max of Date​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
4
[/TD]
[TD]
A​
[/TD]
[TD]
NEW​
[/TD]
[TD]
04/01/2019​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
5
[/TD]
[TD]
B​
[/TD]
[TD]
NEW​
[/TD]
[TD]
06/01/2019​
[/TD]
[/TR]
[TR]
[TD="bgcolor: #DCE6F1"]
6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


M.
 
Upvote 0
Paul,

As you have 50K to 100K rows of data, for the sake of performance i suggest a macro to build column C rather than a formula using COUNTIFS.
Something like this

Code:
Sub aTest()
    Dim dic As Object, vData As Variant, vResult As Variant, i As Long
        
    Set dic = CreateObject("Scripting.Dictionary")
    dic.CompareMode = vbTextCompare
    
    vData = Range("A2:B" & Cells(Rows.Count, "A").End(xlUp).Row)
    vResult = Range("C2:C" & Cells(Rows.Count, "A").End(xlUp).Row)
    For i = 1 To UBound(vData, 1)
        dic(vData(i, 1) & "-" & vData(i, 2)) = ""
       If Not dic.exists(vData(i, 1) & "-" & vData(i, 2) - 1) Then vResult(i, 1) = "NEW"
    Next i
    Range("C2:C" & Cells(Rows.Count, "A").End(xlUp).Row) = vResult
End Sub

M.
 
Upvote 0
Thanks so much M for this. I really do appreciate this. It works great and I have learned something new from reading your code. Thank you again
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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