Display the Number of Occurrences for Each Unique Date in a column

TerryUSA

Board Regular
Joined
Feb 21, 2012
Messages
63
I have a column of dates (Column A) with intermittent blanks and I need to display the number of occurrences for each unique date.




This is what I am starting with: (Note= The number of rows varies by project so I need the whole Column A referenced)

Dates
02-24-2013
02-24-2013
12-15-2012
11-26-2012
02-24-2013
02-24-2013
11-25-2012
11-25-2012

<tbody>
</tbody>
Column A= Dates​



This is how I envision it ending up:

DatesUnique DatesNumber of Occurrences
02-24-201302-24-20134
02-24-201312-15-20121
12-15-201211-26-20121
11-25-20122
11-26-2012
02-24-2013
02-24-2013
11-25-2012
11-25-2012

<tbody>
</tbody>
Column A= Dates
Column B= Unique Dates
Column C= Number of Occurrences for Adjacent Unique Date against Column A

Thanks in advance, Terry
 
Last edited:

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi,

Does this work for you?....

Excel Workbook
ABCD
1DatesUniqueCount*
224/02/201324/02/20134*
324/02/201315/12/20121*
415/12/201226/11/20121*
5*25/11/20122*
626/11/2012***
724/02/2013***
824/02/2013***
925/11/2012***
1025/11/2012***
11****
Sheet4


You will need to change the cell references to suit your layout.
The formula in B2 needs entering with ctrl shift enter NOT just enter, it can then be copied down as far as you require.
The formula in C2 needs to be copied down as far as the formula in B.

The formula in B2 was taken from here.....

How to automatically create a unique distinct list and remove blanks | Get Digital Help - Microsoft Excel resource

I would go with a Pivot Table though.

I hope that helps.

Ak
 
Upvote 0
I don't know Pivot Tables and I just needed something quick.

I thought I couldn't get the formula to work at first, but realized the cells were not formatted as dates and gave weird numbers instead. It worked after fixing that.

You referenced cells A2-A12, I am wanting it to apply to the whole column A no matter how many rows so I don't have to specify ranges each time.
I guess I am looking for more of a Macro that can be run on each new project.

Can this be made into code to do the same thing automatically and for any amount of rows?
 
Upvote 0
Hi Terry,

A Pivot Table will take the following steps to create....

Click in A2
Click Insert.
Click Pivot Table.
Click Existing Worksheet.
Click in the white box.
Click in D1 (or any cell where you want the Pivot Table)
Click Ok.
Drag the Dates to the Row Labels.
Drag the Dates to Values.


I guess the formula I gave you can be altered to the following....

=IFERROR(INDEX($A$2:$A$50000, MATCH(0, IF(ISBLANK($A$2:$A$50000), 1, COUNTIF(B1:$B$1, $A$2:$A$50000)), 0)),"")

=IF(B2="","",COUNTIF($A$2:$A$50000,B2))

Will you really have more than 50,000 rows of data?

You could try this....

=IFERROR(INDEX(A:A, MATCH(0, IF(ISBLANK(A:A), 1, COUNTIF(B1:$B$1, A:A)), 0)),"")

=IF(B2="","",COUNTIF(A:A,B2))

But I don't know if that will work.

Ak
 
Upvote 0
It can. If I wasn't about to head out the door, I would tailor my working code to what you need:
Code:
Private Function PSIDDupeCheck(ByRef wkBook As Workbook, _
    ByRef wkSheet As Worksheet, _
    ByVal wkColumn As Long, _
    ByRef exceptArray() As String, _
    ByRef sendDate As String, _
    ByVal errorSrc As String, _
    Optional ByVal param1 As String, _
    Optional ByVal param2 As String, _
    Optional ByVal param3 As String, _
    Optional ByVal param4 As String) As String
    
    Dim origRange As Range
    Dim rowMax As Long
    Dim filteredRange As Range
    Dim filteredColumn As Long
    Dim filterMax As Long
    Dim areaCount As Long
    Dim dupeRow As Long
    Dim i As Long, j As Long, k As Long
    Dim failReturn As String
    Dim errString As String
    
    If Not wkBook Is Nothing Then
        Set wkSheet = wkBook.Sheets(1)
        If Not wkSheet Is Nothing Then
            rowMax = wkSheet.Range("A65535").End(xlUp).Row  ' Assign last row
            wkSheet.Range("A1:E" & rowMax).Sort _
                key1:=wkSheet.Range("B1"), _
                key2:=wkSheet.Range("A1")
            With wkSheet
                .AutoFilterMode = False
                Set origRange = .Range("A1:" & param1 & rowMax)
                With origRange
    
                    ' Set AutoFilter to screen out non-compared objects
                    .AutoFilter Field:=wkColumn, Criteria1:=Array( _
                        param2, _
                        param3, _
                        param4), _
                        Operator:=xlFilterValues
                        
                    Set filteredRange = .SpecialCells(xlCellTypeVisible)
                    With filteredRange
                        areaCount = .Areas.count   ' 1 for headers, 1 for CG, 1 for Moved/Obstructed
                        Debug.Print .Address(0, 0, , True)
                        filterMax = CountFilteredRows(filteredRange, areaCount, sendDate)
        
                        For i = filterMax To 2 Step -1 ' Delete from bottom to avoid changing row numbers
                        
                            ' Look at the current PSID for any duplicate PSIDs
                            If Application.WorksheetFunction.CountIf(.Range("A1:A" & filterMax), _
                                .Range("A" & i).Value > 1) Then
                                dupeRow = dupeRow + 1
                                Debug.Print "Dupe" & i & "   " & .Range("A" & i).Value
                                ReDim Preserve exceptArray(dupeRow - 1)    ' Adjust array size up by one row
                                exceptArray(dupeRow - 1) = filteredRange.Range("A" & i).Value    ' Record in array
                                
                                ' Once entered into array, write to Exceptions and delete
                                errString = exceptArray(dupeRow - 1) & "              Duplicate PSID record"
                                failReturn = ProblemReport(errString, sendDate)
                                filteredRange.Range("A" & i).EntireRow.Delete ' Delete the dupeValue with the count of 2
                            End If
                        Next i
                    End With    ' filteredRange
                End With    ' origRange
                .ShowAllData
            End With    ' wkSheet
            wkBook.Save
            Application.EnableEvents = True
            PSIDDupeCheck = "Success"
        Else
            errString = errorSrc & "Failed to open worksheet get dupes"
            failReturn = ProblemReport(errString, sendDate)
            Err.Clear
            PSIDDupeCheck = errString
        End If
    Else
        errString = errorSrc & "Failed to open workbook get dupes"
        failReturn = ProblemReport(errString, sendDate)
        Err.Clear
        PSIDDupeCheck = errString
    End If
    wkSheet.AutoFilterMode = False
End Function

The key is the countif command. It takes two parameters, the range over which to look, and what it is looking for. The "> 1" gets you duplicates, so remove that and the VBA should be close.
 
Last edited:
Upvote 0
Hi Terry,

A Pivot Table will take the following steps to create....

Click in A2
Click Insert.
Click Pivot Table.
Click Existing Worksheet.
Click in the white box.
Click in D1 (or any cell where you want the Pivot Table)
Click Ok.
Drag the Dates to the Row Labels.
Drag the Dates to Values.

Thank you that was really easy!

I think it does what I need for the moment, I just need to figure out how to work with it a bit better.

Thanks, Terry
 
Upvote 0
So how could I use this Pivot Table/Graph to show a line graph that trends up (Not up and down)?

I would like the unique dates on bottom and a line starting at the first date and going up the number of occurrences for each unique date. I just want to visualize the total progress over time.
I can make the pivot chart but only seem to get the up and down line between 1-4 and not a running tally over time.
 
Upvote 0





This is what I get, but I want it to add the number of occurrences together as the dates progress. The slope should go from bottom left to upper right.
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,803
Members
448,990
Latest member
rohitsomani

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