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","")

SKUDate
A01/01/2019 NEW
B01/01/2019 NEW
B02/01/2019
A02/01/2019
B03/01/2019
A04/01/2019 NEW
B04/01/2019
A05/01/2019
B06/01/2019 NEW

<tbody>
</tbody>
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
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


A
B
C
1
SKU​
Date​
Is New​
2
A​
01/01/2019​
NEW​
3
B​
01/01/2019​
NEW​
4
B​
02/01/2019​
5
A​
02/01/2019​
6
B​
03/01/2019​
7
A​
04/01/2019​
NEW​
8
B​
04/01/2019​
9
A​
05/01/2019​
10
B​
06/01/2019​
NEW​

<tbody>
</tbody>


Your formula in column C

Pivot Table (filtered by NEW)

A
B
C
2
3
SKU​
Is New​
Max of Date​
4
A​
NEW​
04/01/2019​
5
B​
NEW​
06/01/2019​
6

<tbody>
</tbody>


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,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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