+ Reply to Thread
Results 1 to 29 of 29

COUNTIF - Match amounts and date range

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    COUNTIF - Match amounts and date range

    Perhaps its a silly mistake but attached is my excel sheet with Countif formula used.

    I'd like to return "MATCHED" in Col D only when Amount in Col C FINDS a Complete & Single but Opposing Match (so -101.50 matched to +101.50 and vice versa only but only one for one match) AND also when date in Col A is within 6 days + or _ of date of the found match.

    *actual range of values is in 4000 rows - so its a large table. Col E gives my desired result.

    I tried some suggestions/ formula (pasted in Col D) but it doesn't do the date calculations

    Any help greatly appreciated!
    Attached Files Attached Files
    Last edited by Sean1973; 01-07-2021 at 03:21 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: COUNTIF - Match amounts and date range

    Highight A1 - C44, select FORMULAS and "Create from selection". Will give you three Named Ranges.

    Enter this in D2 and copy down:

    =IF(COUNTIFS(Amount,-C2,Date,">="&A2-6,Date,"<="&A2+6)>0,"Matched","")

    (If there is a record in the file where the amount is the opposite of the value in this row, AND the date in that Col A is within six days either side of the date in this row, Col D says "Matched", otherwise it is blank.)

    Hope this helps

    Ochimus
    Last edited by Ochimus; 01-04-2021 at 08:04 PM.

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Thanks but this returns "Matched" in D9 also which shouldn't happen - see pic Attachment 711627- as it should only match one pair ?

    Also - would this formula work even if sheet is not sorted by dates (ascending or descending)?
    Last edited by Sean1973; 01-04-2021 at 10:46 PM.

  4. #4
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Quote Originally Posted by Ochimus View Post
    Highight A1 - C44, select FORMULAS and "Create from selection". Will give you three Named Ranges.
    Hope this helps
    Ochimus
    Thanks but this returns "Matched" in D9 also which shouldn't happen - see pic here Attachment 711630- as it should only match one pair ?

    Also - would this formula work even if sheet is not sorted by dates (ascending or descending)?

  5. #5
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: COUNTIF - Match amounts and date range

    Apologies for not catching the point that you want only one match, and ignore any subsequent ones.

    Yes, the file will work even if the sheet is not sorted, but will need an extra section to identify the 'match' to be the row with the date closest to the row being compared.

    But what do you want to do if there are two matches the same number of days either side of the row being compared? (E.g. one is two days before the date and the other two days after?)

    Ochimus

  6. #6
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Quote Originally Posted by Ochimus View Post
    Apologies for not catching the point that you want only one match, and ignore any subsequent ones.
    Ochimus
    I didnt quite understand what you mean by "but will need an extra section to identify the 'match' to be the row with the date closest to the row being compared" - If I'm guessing right, you mean the clarification to point below?

    And to ur 2nd point - it should match the nearest days separated entries but if its equal like 2 days on either side of matched date, then it should match the lower (prior) dates, not the higher date. Hope it clarifies.

    Thanks a lot for pitching in!
    Last edited by Sean1973; 01-05-2021 at 09:54 AM.

  7. #7
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: COUNTIF - Match amounts and date range

    Sean1973,

    No, the two points I was asking were separate.

    Assume the database is NOT in Date order and you are checking row 7 with the date of 12 March,
    Assume row 12 is a "mirror" value dated 15 March, and row 31 is also a "mirror" but dated 14 March.
    Do you want Row 12 as the "match" because it is the closest row? Or row 31, because the date is nearer to row 7 than row 12?

    Second point you've answered clearly. Faced with two or more matches the same days either side of a date, use the "earlier" one and ignore the later one.

    Ochimus

  8. #8
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Ochimus - thanks for clarifying

    to point about 2 mirrors when sheet not date sorted - we will always use the date being nearer to the date being matched- the row of placement is disregarded.

  9. #9
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Quote Originally Posted by Ochimus View Post
    Sean1973,
    No, the two points I was asking were separate.
    Ochimus
    Ochimus - thanks for clarifying

    to point about 2 mirrors when sheet not date sorted - we will always use the date being nearer to the date being matched- the row of placement is disregarded.

  10. #10
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    The following will yield "Matched" in only rows 5:6 as displayed in the Desired Outcome:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  11. #11
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Quote Originally Posted by JeteMc View Post
    The following will yield "Matched" in only rows 5:6 as displayed in the Desired Outcome:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Hi- it seems to be off quite a bit! see pic Attachment 712091

    I've also attached a revised sheet- called test rev.xlsx - you can use that to play around data- it has your formula already.

    Thanks
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    This works with the file attached to post #11 in which the data is sorted in ascending date order.
    1. Helper column (you may choose any column and also hide for aesthetic purposes) starting at row 2 and populated using:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    2. Pasted into cell D2 and copied down:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Note that this identifies two additional matches rows 7:12 and 35:39, which seem to me are correct.
    Note that quoting the previous post in not necessary on this forum, a quick reply will work.
    Let us know if you have any questions.

  13. #13
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    JeteMC - thank you so much !

    1. so this will need to work only with that helper column or there's a way it can be integrated to the formula (perhaps integrating with your idea and/or Ochimus above) ?

    2. What mods do I need to make if I want the formula to just find same sign matches across 6 days apart (so duplicates instead of +ive and -ive sign same amounts)? and

    3. does data needs to be sorted ascending order dates first for both above to work?
    Last edited by Sean1973; 01-09-2021 at 08:01 PM.

  14. #14
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    Yes it will only work with the helper column.
    To find same sign matches across 6 days apart modify the helper column formula to read: =AGGREGATE(15,6,ROW(A$1:A1)/(C$1:C1=C2)/(A$1:A1>=A2-6),1)
    Yes the data needs to be sorted in ascending order by date.
    Let us know if you have any questions.

  15. #15
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    np...I'll deal with helper col. Thanks a lot for pitching in - How do I mark this solved?

  16. #16
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    You're Welcome and thank you for the feedback. To mark the thread as 'Solved' use the thread tools menu above your first post. I hope that you have a blessed day.

  17. #17
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Red face Re: COUNTIF - Match amounts and date range

    JeteMc - You got a great attitude man ! keep it up.
    I saw some folks another forum - believe help and obnoxiousness, cant be separated.

    BTW - I just saw that I cant send PMs - wud you know the reason for that?
    Last edited by Sean1973; 01-10-2021 at 07:50 PM.

  18. #18
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    commented for update
    Last edited by Sean1973; 08-02-2021 at 05:20 PM.

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: COUNTIF - Match amounts and date range

    Attach a workbook showing the problem … It’s been a while!
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  20. #20
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    ...somehow cant delete this post....
    Last edited by Sean1973; 08-03-2021 at 10:48 AM.

  21. #21
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Quote Originally Posted by JeteMc View Post
    You're Welcome and thank you for the feedback. To mark thread as 'Solved' use thread tools menu above your first post.
    Hi- so when working with 2 formlaes that @JeteMc suggested (in post #12, helper column & test column), with good size sample set/rows, formulas seems to be mis-firing right off the bat.

    I'm attaching the sheet -it also has desired results for first 130 or so rows, given in Green colored Column. Purpose is really trying to match opposing sign (+ive & -ive) but Same Amount values in Col C, when dates are within 6 days of date values in Col A. SO matches will always come in pairs only.
    Attached Files Attached Files
    Last edited by Sean1973; 08-04-2021 at 12:02 AM.

  22. #22
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    Here is a revised formula for column E:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The results in column D are now mostly the same as those in column F.
    There are some exceptions such as -74.12 in row 23. The date in A23 is 7/18/2019 and I don't see 74.12 in the date range 7/12/2009 to 7/24/2019.
    Let us know if you have any questions.

  23. #23
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Thanks - this seems to work much better but I also tested from bottom rows and even though I see ur helper column displaying the matched row- formulae fails to place label in Col D for some rows. I didnt check all but hope I did isolate the issue. here're the rows # 1914, 1883, 1845, 1803, 1780. I've attached the revised sheet also so you'll see it.

    And to find same sign matches across 6 days apart, you had suggested helper column formula =AGGREGATE(15,6,ROW(A$1:A1)/(C$1:C1=C2)/(A$1:A1>=A2-6),1) ; how wud the new formula need be adapted for that?
    Attached Files Attached Files
    Last edited by Sean1973; 08-05-2021 at 10:19 PM.

  24. #24
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    Modify the formula in cells D2 and down to read:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.

  25. #25
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    Thanks JeteMc - this works. And what formulae change I need to make to find SAME SIGN Matches (not Opposite), again upto 6 days apart?

  26. #26
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    While still looking for a way to find same sign matches, I discovered that the opposite sign formula needs modifying:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.

  27. #27
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    thanks...let me try this

  28. #28
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,556

    Re: COUNTIF - Match amounts and date range

    The following seems to be finding the same sign matches:
    1. In G2 and down: =IF(OR(ISNUMBER(H2),COUNTIFS(H$2:H2,ROW())),"MATCHED","")
    2. In H2 and down: =SUM(AGGREGATE(15,6,(ROW(A3:A$1990)-ROW(A2))/(C3:C$1990=C2)/(ISODD(COUNTIFS(C$1:C2,C2,A$1:A2,">="&A2-6)))/(A3:A$1990<=A2+6),1),ROW())
    Let us know if you have any questions.
    Attached Files Attached Files

  29. #29
    Registered User
    Join Date
    12-18-2012
    Location
    canada
    MS-Off Ver
    Excel 2019
    Posts
    20

    Re: COUNTIF - Match amounts and date range

    thanks- will check it out with another dataset

+ 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] Identify Equal & Opposing Sign Totals
    By jewelsharma in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-17-2016, 03:51 AM
  2. [SOLVED] Best price added to corresponding fiqure in opposing column
    By SusanWi in forum Excel General
    Replies: 14
    Last Post: 12-20-2015, 11:15 AM
  3. Replies: 6
    Last Post: 03-16-2015, 04:40 PM
  4. Counif using dates
    By wjk221 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-14-2014, 04:32 PM
  5. [SOLVED] Match dates in column B with column A across worksheets and sum any amounts in column G
    By daddywine in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-04-2012, 01:07 AM
  6. [SOLVED] I cant understand this formula (index+match+counif)
    By Alexander_Golinsky in forum Excel General
    Replies: 3
    Last Post: 05-08-2012, 08:04 AM
  7. Replies: 1
    Last Post: 06-15-2010, 09:42 PM

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