Formula Creation Help

MrHopeless

New Member
Joined
Dec 22, 2022
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Excel Test.JPG



Hello- I need help with trying to get a formula to do the following:

If(B12 = "New Lease", figure out the duration for Occupant John Doe from C8 to D11). However, I do not want it to capture the Occupant, Paula Doe. Or, I am ok with doing a separate column to calculate the duration of the Occupants and plugging those results into my other formula.

Thank you
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
2 of those items has a duration of longer than a year. What kind of result are you looking to return?
If it was always a year, you could just do a COUNTIF
 
Last edited:
Upvote 0
2 of those items has a duration of longer than a year. What kind of result are you looking to return?
If it was always a year, you could just do a COUNTIF
The result would be the total duration of how long the occupant has lived in the unit in years and days.
 
Upvote 0
All the leases duration of each occupants are continuous ?
If true, the job will be easier.
We can get the duration by The last lease End minus the first lease Start.
 
Upvote 0
All the leases duration of each occupants are continuous ?
If true, the job will be easier.
We can get the duration by The last lease End minus the first lease Start.
Yes it is. I would like the formula to provide the duration for each prior occupant every time Col B shows a "New Lease". For example, when Jane Doe moved in with a "New Lease" on 9/9/2022, it will calculate the duration of time John Doe lived in the apartment from 12/10/2015-6/15/2021. But, make sure it doesn't track the first occupant Paula Doe and only does John Doe.
 
Upvote 0
Try to put the code below in the cell E5.
Maybe you should press "Ctrl+Shift+Enter" instead of "Enter".
Then copy downward to the last row.

I assume the data sort according to occupant and the first lease is always new one.

Excel Formula:
=IFERROR(DATEDIF(IF(A5<>A4,MIN(IF($A$5:$A$12=A5,$C$5:$C$12,7^7)),""),IF(A5<>A4,MAX(IF($A$5:$A$12=A5,$D$5:$D$12,0))+1,""),"Y") &"y"&DATEDIF(IF(A5<>A4,MIN(IF($A$5:$A$12=A5,$C$5:$C$12,7^7)),""),IF(A5<>A4,MAX(IF($A$5:$A$12=A5,$D$5:$D$12,0))+1,""),"YM")&"m"&DATEDIF(IF(A5<>A4,MIN(IF($A$5:$A$12=A5,$C$5:$C$12,7^7)),""),IF(A5<>A4,MAX(IF($A$5:$A$12=A5,$D$5:$D$12,0))+1,""),"MD")&"d","")
 
Upvote 0
Try to put the code below in the cell E5.
Maybe you should press "Ctrl+Shift+Enter" instead of "Enter".
Then copy downward to the last row.

I assume the data sort according to occupant and the first lease is always new one.

Excel Formula:
=IFERROR(DATEDIF(IF(A5<>A4,MIN(IF($A$5:$A$12=A5,$C$5:$C$12,7^7)),""),IF(A5<>A4,MAX(IF($A$5:$A$12=A5,$D$5:$D$12,0))+1,""),"Y") &"y"&DATEDIF(IF(A5<>A4,MIN(IF($A$5:$A$12=A5,$C$5:$C$12,7^7)),""),IF(A5<>A4,MAX(IF($A$5:$A$12=A5,$D$5:$D$12,0))+1,""),"YM")&"m"&DATEDIF(IF(A5<>A4,MIN(IF($A$5:$A$12=A5,$C$5:$C$12,7^7)),""),IF(A5<>A4,MAX(IF($A$5:$A$12=A5,$D$5:$D$12,0))+1,""),"MD")&"d","")

I appreciate the effort but it did not do what I was expecting. It calculated the duration from the first occupant to the last. It should be from the John Doe occupant and not including Paula Doe. The formula should be based on the type of lease and not the occupants. The reason being is that there could be multiple occupants and some would stay or leave on the next Lease Renewal.

If the the cell reads "New Lease", then figure out the duration of the prior tenant John Doe from 12/10/2015-6/15/2021 and not include Paula Doe. Or, I can work with a formula that provides the duration of the occupants from their "New Lease" to the next "New Lease".

Sorry if this is a pain.


Excel Test.JPG
 
Upvote 0
Try:
Book1
ABCDE
1
2
3OccupantType of leaseLease StartLease End
4
5Paula DoeNew Lease12/10/201212/9/2013 
6Paula DoeLease Renewal12/10/201312/9/2014 
7Paula DoeLease Renewal12/10/201412/9/20152 Yr 11 Months 29 Days
8John DoeNew Lease12/10/201512/9/2016 
9John DoeLease Renewal12/10/201612/9/2017 
10John DoeLease Renewal12/10/201712/9/2019 
11John DoeLease Renewal3/16/20206/15/20215 Yr 6 Months 5 Days
12Jane DoeNew Lease9/9/20219/8/20220 Yr 11 Months 30 Days
Sheet1
Cell Formulas
RangeFormula
E5:E12E5=IF(A6=A5,"",DATEDIF(MIN(FILTER($C$5:$C$12,($A$5:$A$12=A5))),MAX(FILTER($D$5:$D$12,($A$5:$A$12=A5))),"y")&" Yr "&DATEDIF(MIN(FILTER($C$5:$C$12,($A$5:$A$12=A5))),MAX(FILTER($D$5:$D$12,($A$5:$A$12=A5))),"ym")&" Months "&DATEDIF(MIN(FILTER($C$5:$C$12,($A$5:$A$12=A5))),MAX(FILTER($D$5:$D$12,($A$5:$A$12=A5))),"md")&" Days ")
 
Upvote 0
Try:
Book1
ABCDE
1
2
3OccupantType of leaseLease StartLease End
4
5Paula DoeNew Lease12/10/201212/9/2013 
6Paula DoeLease Renewal12/10/201312/9/2014 
7Paula DoeLease Renewal12/10/201412/9/20152 Yr 11 Months 29 Days
8John DoeNew Lease12/10/201512/9/2016 
9John DoeLease Renewal12/10/201612/9/2017 
10John DoeLease Renewal12/10/201712/9/2019 
11John DoeLease Renewal3/16/20206/15/20215 Yr 6 Months 5 Days
12Jane DoeNew Lease9/9/20219/8/20220 Yr 11 Months 30 Days
Sheet1
Cell Formulas
RangeFormula
E5:E12E5=IF(A6=A5,"",DATEDIF(MIN(FILTER($C$5:$C$12,($A$5:$A$12=A5))),MAX(FILTER($D$5:$D$12,($A$5:$A$12=A5))),"y")&" Yr "&DATEDIF(MIN(FILTER($C$5:$C$12,($A$5:$A$12=A5))),MAX(FILTER($D$5:$D$12,($A$5:$A$12=A5))),"ym")&" Months "&DATEDIF(MIN(FILTER($C$5:$C$12,($A$5:$A$12=A5))),MAX(FILTER($D$5:$D$12,($A$5:$A$12=A5))),"md")&" Days ")
Sh*t my work computer only has Excel 2016 which doesn't have the FILTER formula. Your formula looks spot on but of course I can't use it at my job (which is where I need it). I assume there is no alternative to this formula without the "FILTER" formula?
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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