If statement with date range

Mike820

New Member
Joined
Jul 24, 2019
Messages
21
Hi, I currently have data organized similar to below. I'm struggling to write a formula. I'm trying to do the following: if the oldest date tied to an ID is within the last 13 months then return "New" if the oldest date is older than 13 months then sum all the amounts for that relationship ID and if it's a positive number then return "In" if negative return "out".


IDDateAmountFormula column
112/1/20191000New
15/2/2019-2500New
211/5/20175000In
22/2019-3000In
33/2/2016-5000Out
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
This should do it
Book123.xlsm
ABCD
1IDDateAmountFormula column
2101/12/20191000New
3102/05/2019-2500New
4205/11/20175000in
52Feb-19-3000in
6302/03/2016-5000out
Sheet10
Cell Formulas
RangeFormula
D2:D6D2=IF(DATEDIF(MAXIFS($B$2:$B$6,$A$2:$A$6,A2),TODAY(),"M")<13,"New",IF(SUMIFS($C$2:$C$6,$A$2:$A$6,A2)<0,"out","in"))
 
Upvote 0
Thank you, this seems like what I'm looking for but what if I'd like to set a date myself instead of using the Today function. For example, "New" would be any account February 2018 and newer?
 
Upvote 0
In that case, just replace TODAY() with a reference to a cell that contains your set date.
Remember that if you only enter month and year that it will evaluate from the first day of the month, not the last.
 
Upvote 0
In that case, just replace TODAY() with a reference to a cell that contains your set date.
Remember that if you only enter month and year that it will evaluate from the first day of the month, not the last.

Thank you for all your help, the last formula worked flawlessly, I had to change the formula to MINIFS for what I needed. I have an additional caveat I'd like to include in the previous formula you provided, wondering if you could help.

1) Creation of an additional segment called "Closed" as shown in ID 5 below: if all Tags for an ID is "Closed" then return "Closed". The formula you provided for "New" will always take precedent shown in ID 4 below but if it's not "Closed" or "New" then it follows same rules for "In" or "Out".


Thanks

IDDateAmountTagFormula column
112/1/20191000InNew
15/2/2019-2500outNew
211/5/20175000InIn
22/2019-3000outIn
33/2/2016-5000OutOut
46/5/2017-1000ClosedNew
43/1/2019200ClosedNew
55/2017500ClosedClosed
52/2017-1000ClosedClosed
 
Upvote 0
What exactly are you using for formula and criteria (i.e. set date for new) with the example above?

I can't see why ID 4 is new and ID 2 is not, changing MAXIFS to MINIFS doesn't appear to make any difference to the results.
 
Upvote 0
What exactly are you using for formula and criteria (i.e. set date for new) with the example above?

I can't see why ID 4 is new and ID 2 is not, changing MAXIFS to MINIFS doesn't appear to make any difference to the results.

Providing some additional background: each month a new report is generated and I need to insert the formula to generate these 4 segments (New, Closed, In, and Out). So let’s say the report was generated month end Mar 2020. I’d want to tag any IDs as New if the oldest (earliest) date was within the last 13 months from Mar 2020. In the April report, I’d want to tag anything as New if the oldest Date within an ID was within 13 months from April 2020 etc. the formula was returning an error using MAXif in certain case but it worked when I changed it to Minif and practically thinking about it, Min seems like the correct way I should be approaching it.
 
Upvote 0
In the March report I'm currently using the formula below. I changed MAXIFS to MINIFS and also the date for whatever month I'm working in. So this would return "New" any ID's where the oldest (earliest) date was within the last 13 months from March 31 2020, so basically any dates from March 31 2020 to March 1 2019.

=IF(DATEDIF(MINIFS($B$2:$B$6,$A$2:$A$6,A2),"31 Mar 2020","M")<13,"New",IF(SUMIFS($C$2:$C$6,$A$2:$A$6,A2)<0,"out","in"))
 
Upvote 0
So why is ID 4 'New' in the example?

Based on the description that you have provided it should either be 'Out' or 'Closed'
 
Upvote 0
So why is ID 4 'New' in the example?

Based on the description that you have provided it should either be 'Out' or 'Closed'

You are correct. This should be tagged as Closed. I meant to have the date as 6/5/2019 not 6/5/2017 for this example of show it would be tagged as New. But you are correct in ID 4 this would be Closed because the oldest date is 6/5/2017 outside of the 13 month window and all “tags” are “Closed” for this ID.
 
Upvote 0

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

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