To shorten a lengthy formula

SanjayaGarg

New Member
Joined
Nov 10, 2017
Messages
22
Office Version
  1. 2013
Platform
  1. Windows
I made a very simple formula in column P (Tenure Completed on) , but the formula is very lengthy as it covers from column V to column AB. Can this be shortened with same function. Formula is as under :

'=IF(N2="","",IF(V2="",O2,IF(AND(W2="",K2="year"),DATE(YEAR(V2)+J2,MONTH(V2),DAY(V2)-1),IF(AND(W2="",K2="months"),DATE(YEAR(V2),MONTH(V2)+J2,DAY(V2)-1),IF(AND(W2="",K2="days"),DATE(YEAR(V2),MONTH(V2),DAY(V2)+J2-),IF(AND(X2="",K2="year"),DATE(YEAR(W2)+J2,MONTH(W2),DAY(W2)-1),IF(AND(X2="",K2="months"),DATE(YEAR(W2),MONTH(W2)+J2,DAY(W2)-1),IF(AND(X2="",K2="days"),DATE(YEAR(W2),MONTH(W2),DAY(W2)+J2-),IF(AND(Y2="",K2="year"),DATE(YEAR(X2)+J2,MONTH(X2),DAY(X2)-1),IF(AND(Y2="",K2="months"),DATE(YEAR(X2),MONTH(X2)+J2,DAY(X2)+J2-),IF(AND(Y2="",K2="days"),DATE(YEAR(X2),MONTH(X2),DAY(X2)-1),IF(AND(Z2="",K2="year"),DATE(YEAR(Y2)+J2,MONTH(Y2),DAY(Y2)-1),IF(AND(Z2="",K2="months"),DATE(YEAR(Y2),MONTH(Y2)+J2,DAY(Y2)-1),IF(AND(Z2="",K2="days"),DATE(YEAR(Y2),MONTH(Y2),DAY(Y2)+J2-),IF(AND(AA2="",K2="year"),DATE(YEAR(Z2)+J2,MONTH(Z2),DAY(Z2)-1),IF(AND(AA2="",K2="months"),DATE(YEAR(Z2),MONTH(Z2)+J2,DAY(Z2)-1),IF(AND(AA2="",K2="days"),DATE(YEAR(Z2),MONTH(Z2),DAY(Z2)+J2-1),"")))))))))))))))))

Table is as under :

JKL
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
AA
AB
1TenurePeriod
Joining Date
Initial tenure completed on
Tenure Completed on
Extn 1
Extn 2
Extn 3
Extn 4
Extn 5
Extn 6
Extn 7
2​
44​
days​
13-03-2020​
25-04-2020​
23-10-2021​
14-05-2020​
27-06-2020​
10-08-2020​
23-09-2020​
06-11-2020​
20-12-2020​
02-02-2021​
3​
5​
year​
13-03-2020​
25-04-2020​
23-10-2021​
14-05-2020​
27-06-2020​
10-08-2020​
23-09-2020​
06-11-2020​
20-12-2020​
02-02-2021​
4​
3​
months​
13-03-2020​
25-04-2020​
23-10-2021​
14-05-2020​
27-06-2020​
10-08-2020​
23-09-2020​
06-11-2020​
20-12-2020​
02-02-2021​
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I doubt that anyone would want to pick that broken formula apart when you could quite easily tell is in simple terms what it should be doing.
 
Upvote 0
How about:

Book1
JKLMNOPQRSTUVWXYZAAAB
1TenurePeriodJoining DateInitial Tenure completed onTenure Completed onExtn 1Extn 2Extn 3Extn 4Extn 5Extn 6Extn 7
244days3/13/20204/25/20202/1/20215/14/20206/27/20208/10/20209/23/202011/6/202012/20/2020
35year3/13/20204/25/202011/5/20255/14/20206/27/20208/10/20209/23/202011/6/2020
43months3/13/20204/25/202011/9/20205/14/20206/27/20208/10/2020
Sheet1
Cell Formulas
RangeFormula
P2:P4P2=IF(N2="","",IF(V2="",O2,IF(K2="days",LOOKUP(9^9,V2:AB2)+J2,EDATE(LOOKUP(9^9,V2:AB2),J2*IF(K2="Year",12,1)))-1))
 
Upvote 0
Solution
Thanks Eric. You provided me exactly what I wanted. Can you please explain functioning of this formula e.g. what is meant by 9^9 and how it is calculating if there is 'months' in K2 coz you have not mentioned months in the formula. Thanks a lot again for saving my day.
 
Upvote 0
not mentioned months in the formula.
The formula doesn't need to check months. Days and Years are checked, if K2 is neither of those then it must be months.
what is meant by 9^9
That is a quick way of writing 387420489. When looking for the last date in a row / column you just need to look for a number that is greater than the largest possible date serial. In reality, a number around 50000 is adequate for current dates but it is common to go much larger to prevent future errors.
 
Upvote 0
The formula doesn't need to check months. Days and Years are checked, if K2 is neither of those then it must be months.

That is a quick way of writing 387420489. When looking for the last date in a row / column you just need to look for a number that is greater than the largest possible date serial. In reality, a number around 50000 is adequate for current dates but it is common to go much larger to prevent future errors.
OK. Thanks a lot for solution & explaining it nicely. Thanks once again
 
Upvote 0
You're welcome!

Although you should really mark @Eric W's post as the solution, mine was only an explanation of his formula that you asked for.
 
Upvote 0
Using LOOKUP and a number bigger than any number in the range is a trick to get the rightmost value in the range. And as Jason explained, 9^9 is a quick way to write a very big number. But I noticed that all your dates in that range are in increasing order. If so, then the rightmost date will also be the maximum. Then we can shorten the formula a bit:

Excel Formula:
=IF(N2="","",IF(V2="",O2,IF(K2="days",MAX(V2:AB2)+J2,EDATE(MAX(V2:AB2),J2*IF(K2="Year",12,1)))-1))

Glad we could help!
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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