How to calculate the number of days between two dates dependent on criteria

JENKELLY

New Member
Joined
Jan 22, 2019
Messages
5
Hi
I have the following data (this is an example - there are approx 45000 rows in the original doc which will only increase with time!):
Cust NoEnd of Period Date Carried Forward Balance
JH32019-01-071032.06
JH32018-12-071130.82
JH32018-12-071732.06
JH32018-12-071132.06
JH32018-11-121230.82
RB52019-01-071182.76
RB52018-12-071082.76
RB52018-12-07982.76
RB52018-12-0740.14
RB52018-11-12611.45
RB52018-10-03-1.17
RB52018-09-04570.14
RB52018-08-1440.14
RB52018-07-04-1.17
YT62019-01-071020.53
YT62018-12-071020.53
YT62018-12-071020.53
YT62018-12-07510.25
YT62018-11-121020.53
YT62018-10-03510.25
YT62018-09-04-0.03
YT62018-08-14510.25
YT62018-07-04-0.03
YT62018-06-05-0.03

<colgroup><col><col><col></colgroup><tbody>
</tbody>

I am trying to find the length of time in days that the customer has been in arrears from the most recent end of period date - i.e. back to where their account goes into credit (if it does) or until their account was opened if it has always been in debt. I'm only interested in the current instance of debt (i.e. it doesn't matter if they have been in arrears before) and would like the data to look like this:
Cust NoDays in arrears
JH356
RB556
YT696

<colgroup><col><col></colgroup><tbody>
</tbody>

The data is exported out and refreshed, so needs to be able to cope with this.
Any help is much appreciated!

Thank you :)

Jenny
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi. Before anyone can really answer where does 56 come from? Im struggling to see how the first two customers can both produce the same number based on your data and explanation.
 
Upvote 0
try this, revise range to suit


Book1
ABCDEF
1Cust NoEnd of Period DateCarried Forward Balance
2JH307/01/20191032.06JH356
3JH307/12/20181130.82RB556
4JH307/12/20181732.06YT696
5JH307/12/20181132.06
6JH312/11/20181230.82
7RB507/01/20191182.76
8RB507/12/20181082.76
9RB507/12/2018982.76
10RB507/12/201840.14
11RB512/11/2018611.45
12RB503/10/2018-1.17
13RB504/09/2018570.14
14RB514/08/201840.14
15RB504/07/2018-1.17
16YT607/01/20191020.53
17YT607/12/20181020.53
18YT607/12/20181020.53
19YT607/12/2018510.25
20YT612/11/20181020.53
21YT603/10/2018510.25
22YT604/09/2018-0.03
23YT614/08/2018510.25
24YT604/07/2018-0.03
25YT605/06/2018-0.03
Sheet3
Cell Formulas
RangeFormula
F2{=MAXIFS($B$2:$B$25,$A$2:$A$25,E2)-IFERROR(INDEX($B$2:$B$25,MATCH(TRUE,IF($A$2:$A$25=E2,$C$2:$C$25)<0,0)-1),MINIFS($B$2:$B$25,$A$2:$A$25,E2))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Hi
Thanks for responding so quickly.

The first customer (JH3) has always been in debt, so the days are calculated by 2019-01-07 take away 2018-11-12 is 56 days.

The second customer (RB5) has only been in debt since 2018-11-12. Prior to that, their account was in credit. I just need to know the period they are in debt so, again, 2018-11-12 taken away from 2019-01-07 is 56 days.

Does that make sense?

Thanks :)
Jenny
 
Upvote 0
Hi AlanY,

That is pretty fricking awesome! Thank you very much - works like a charm! It's been driving me bonkers for some time now. I have no idea how that works, but it's great!

Wishing I had your brain...

Jenny
 
Upvote 0
you're welcome.

and, you don't.
 
Upvote 0
Hi AlanY
I've just spotted an anomaly...which is my fault as I didn't include this in the original data. Where a customer is not in arrears currently (i.e. showing a negative amount on 07/01/2019), the array produces an incorrect result. Is there a way round this?
Thanks again.
Jenny
 
Upvote 0
modified to suit


Book1
ABCDEF
1Cust NoEnd of Period DateCarried Forward Balance
2JH307/01/20191032.06JH356
3JH307/12/20181130.82RB556
4JH307/12/20181732.06YT696
5JH307/12/20181132.06AY1---
6JH312/11/20181230.82
7RB507/01/20191182.76
8RB507/12/20181082.76
9RB507/12/2018982.76
10RB507/12/201840.14
11RB512/11/2018611.45
12RB503/10/2018-1.17
13RB504/09/2018570.14
14RB514/08/201840.14
15RB504/07/2018-1.17
16YT607/01/20191020.53
17YT607/12/20181020.53
18YT607/12/20181020.53
19YT607/12/2018510.25
20YT612/11/20181020.53
21YT603/10/2018510.25
22YT604/09/2018-0.03
23YT614/08/2018510.25
24YT604/07/2018-0.03
25YT605/06/2018-0.03
26AY107/01/2019-1032.06
27AY107/12/2018-1130.82
28AY107/12/20181732.06
Sheet3
Cell Formulas
RangeFormula
F2{=IF(INDEX($C$2:$C$28,MATCH(E2&"|"&MAXIFS($B$2:$B$28,$A$2:$A$28,E2),$A$2:$A$28&"|"&$B$2:$B$28,0))<0,"---",MAXIFS($B$2:$B$28,$A$2:$A$28,E2)-IFERROR(INDEX($B$2:$B$28,MATCH(TRUE,IF($A$2:$A$28=E2,$C$2:$C$28)<0,0)-1),MINIFS($B$2:$B$28,$A$2:$A$28,E2)))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
That's excellent. Thank you so much for your help. I will endeavour to try and understand what it all means!!! Jenny :)
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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