+ Reply to Thread
Results 1 to 7 of 7

Count if is in a range date of month and delete duplicates

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2023
    Location
    Mexico
    MS-Off Ver
    Microsoft 365
    Posts
    1

    Count if is in a range date of month and delete duplicates

    Hello everyone.

    I want to count how many "codes" I have but removing the duplicated within the number of the month (jan,feb,etc) according to a date given to each code.

    Basically the attached document is the data I'm using.

    Hope somebody can help,
    thanks in advice
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Count if is in a range date of month and delete duplicates

    If I understand you correctly, you only want to count unique combinations of date and code. So when code 1000047549 appears twise on 23-Jan, that should only be counted once. If I have interpreted corrently, then...

    There's probably a cleverer way, but this is reasonably clear to read...
    In the attached:
    Column D: To identify the month from the date, use MONTH(). NB you need to be a bit cleverer if you want this to roll over into the new year. As written, it'll add up Januaries across all years.
    Column E: Generates a composite text value, combining code and date. It doesn't need the TEXT function or the slash, but that makes it easier to see what's going on.
    Column F: The key bit in this column is where the $$ go. F3 contains =COUNTIFS($E$3:E3,E3). When you copy that down, you get =COUNTIFS($E$3:E4,E4) and so on. Short version is, you get a running total of the number of times that unique Code/Date combination has happened.

    Column I: I just put the month numbers in to make the formula easy to copy.
    Column J: =COUNTIFS(D:D,I3,F:F,1). This counts the number of times you have the right month, but only counts the first instance of a code/date combo, by looking for a 1 in column F.
    Attached Files Attached Files
    Kind Regards,

    Out of the Hat

    "Computers are stupid - they do EXACTLY what you tell them to"

    If I've helped you with a problem, please say thanks by clicking the small star icon on the left.

  3. #3
    Valued Forum Contributor
    Join Date
    10-17-2010
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013, 2016, 2019, 365
    Posts
    294

    Re: Count if is in a range date of month and delete duplicates

    ...and having re-read your post, there is a chance that you just want to count the number of unique codes happening in the month. (So would count a code only once if it happens on 2 different days in the month). I have added a couple of extra columns. Same principle, just a different composite to check for duplicates. Happens to return the same results on your data set.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    12-09-2014
    Location
    Trakai, Lithuania
    MS-Off Ver
    2016
    Posts
    1,408

    Re: Count if is in a range date of month and delete duplicates

    Power Query
    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type number}, {"Date", type datetime}}),
        #"Extracted Month Name" = Table.TransformColumns(#"Changed Type", {{"Date", each Date.MonthName(_), type text}}),
        #"Removed Duplicates" = Table.Distinct(#"Extracted Month Name"),
        #"Grouped Rows" = Table.Group(#"Removed Duplicates", {"Date"}, {{"Count", each Table.RowCount(_), type number}})
    in
        #"Grouped Rows"
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Count if is in a range date of month and delete duplicates

    Try, F3=COUNTA(UNIQUE(FILTER($B$3:$B$40,TEXT($C$3:$C$40,"mmmm")=E3))), copy down.

  6. #6
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Count if is in a range date of month and delete duplicates

    Modified above formula, =IFERROR(IF(MATCH(E3,TEXT(C3:C40,"mmmm"),0),COUNTA(UNIQUE(FILTER($B$3:$B$40,TEXT($C$3:$C$40,"mmmm")=E3)))),0)

  7. #7
    Forum Expert
    Join Date
    09-25-2015
    Location
    Milan Italy
    MS-Off Ver
    office 365
    Posts
    1,988

    Re: Count if is in a range date of month and delete duplicates

    F3=IFERROR(ROWS(UNIQUE(FILTER($B$3:$B$40,(MONTH($C$3:$C$40)=MONTH($E3&0))*($C$3:$C$40<>"")))),"")

    Copy down

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Count days by month in a date range
    By dimitrisheets in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-16-2020, 01:15 PM
  2. Count how many that only relate to a month date range in a column of dates
    By leemcguigan in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-03-2019, 10:13 PM
  3. count date range month wise
    By pblnrao in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-18-2018, 03:36 AM
  4. [SOLVED] Count Occurrences Date Range Falls Within Month
    By Rbooth in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-25-2014, 06:47 PM
  5. [SOLVED] Count the days excluding Friday in every month using a date range.
    By miss_chloe in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-23-2013, 10:42 AM
  6. Count Month Occurrence in range of date
    By Bob@Sun in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-18-2010, 05:20 AM
  7. Count the occurances of a month in a range of date fields
    By Keith Brown in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-14-2005, 08:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1