+ Reply to Thread
Results 1 to 9 of 9

Counting dates before a specific date and event

  1. #1
    Forum Contributor
    Join Date
    05-09-2019
    Location
    South West
    MS-Off Ver
    365
    Posts
    108

    Counting dates before a specific date and event

    Hello,

    I?m wondering if someone might be able to help.
    I have 2 datasets in a large sheet I?m working in. The first sheet lists all the emails sent out to customers (1 row per email), the other sheet lists all purchases made (1 row per purchase).

    What I am trying to do, is count the number of emails that were sent to a person, prior to them making a purchase. However, whilst 1 person may have received 2 emails, and both emails were sent before their 2 purchases, if 1 email was sent before purchase 1, and the other email sent before purchase 2, I want to record this as the person having received only 1 email before each separate purchase?.not sure if I?ve explained this very well, but hopefully my attached example shows this better, and uses actual dates from my data, and the order in which they appear.

    Column G shows the results I?m trying to achieve with a formula?..if this is possible.

    Thanks in advance if anyone has taken the time to read this !
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Counting dates before a specific date and event

    In G4, use

    =COUNTIFS(A:A,E4,B:B,"<"&F4,B:B,">"&IFERROR(1/(1/MAXIFS(F:F,F:F,"<"&F4)),F4))

    and copy down.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,435

    Re: Counting dates before a specific date and event

    I don't understand why there is in your sample a difference between the numbers of E-mails on Purchase date 21/01/2023 and 31/01/2023.

    What applies to 31/01/2023 also applies to 21/01/2023.

    This formula calculates the number of emails the person received before the purchase date:

    Please try in G4 and copy down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    05-09-2019
    Location
    South West
    MS-Off Ver
    365
    Posts
    108

    Re: Counting dates before a specific date and event

    Hi Bernie ,

    Thanks so much for your time and taking a look at this. The formula worked perfectly in the sample data, but isn't working in my actual data....I will need to try and work out what's going on, as I set the sample data up very similar to my actual data.

  5. #5
    Forum Contributor
    Join Date
    05-09-2019
    Location
    South West
    MS-Off Ver
    365
    Posts
    108

    Re: Counting dates before a specific date and event

    Hi HansDouwe,

    Thank you for your reply. Whilst I do understand where you are coming from, this is the logic I need to work with in my data, and so the expected results I put in the sample data, is the results I would need to achieve.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Counting dates before a specific date and event

    Share a smallish set of actual data, removing any sensitive values. Show what my formula is giving and why you think it isn't working.

    One thing to look at is whether your dates are dates only or date-times, like 9/14/2023 14:49:32 that are formatted to only show the date. That can require slightly different logic for the comparisons.
    Last edited by Bernie Deitrick; 09-14-2023 at 02:50 PM.

  7. #7
    Forum Contributor
    Join Date
    05-09-2019
    Location
    South West
    MS-Off Ver
    365
    Posts
    108

    Re: Counting dates before a specific date and event

    Hi Bernie,

    strangely, when I did try and copy out actual data (stripping our sensitive info), the formula worked just fine ! So I can't even seem to be able to replicate the issue I'm having in my "live" data set in an example I've tried it again a number of times, but I keep getting 0 as a result in my data. The only difference is that in my "live" data I have many more columns and the data is held on 2 different tabs, rather than just one.

    Think I may have to rethink how I do this (but I can see that your formula does do the job I needed it to do though !)

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Counting dates before a specific date and event

    Look for mismatched key values - an extra space at the end of a name, for example. You can use =MATCH(cell, other column, False) and if that returns an error the value in the cell doesn't match values in your other column. Also, look for errors in any of the columns (use Ctrl-G Special Formulas/Constants Error values) Those can mess up formulas as well....

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,947

    Re: Counting dates before a specific date and event

    I think I left out a filter from the MAXIFS; one that finds dates for the specific customer:

    =COUNTIFS(A:A,E4,B:B,"<"&F4,B:B,">"&IFERROR(1/(1/MAXIFS(F:F,F:F,"<"&F4,E:E,E4)),F4))

+ 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. [SOLVED] Counting transactions per specific dates
    By ALLANT in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-28-2017, 10:50 PM
  2. [SOLVED] Counting specific days between dates
    By floxxie in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-14-2014, 08:44 AM
  3. [SOLVED] Return the specific Date of an event
    By Emou in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-16-2012, 05:28 PM
  4. Counting when a date falls between two specific dates
    By ant7629 in forum Excel General
    Replies: 2
    Last Post: 10-20-2012, 02:29 AM
  5. counting unique entries for a specific date period in a series of dates
    By woody382 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-16-2010, 01:57 PM
  6. Replies: 3
    Last Post: 10-16-2008, 02:46 PM
  7. [SOLVED] Counting occurences of a specific day between two dates
    By coal_miner in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-20-2005, 11:06 AM

Tags for this Thread

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