How to add an IF statement to a formula that returns the number of months between two dates
Hello Community,
I'm trying to write a formula that returns the number of months remaining in a term if a date is provided, and if no date return "NA".
I have =ROUND((NETDAYS(TODAY(), [Lease Expiration]@row) / 365) * 12), but not sure how to make this formula return "NA" on blanks instead of an error:
Best Answers
-
This should do the trick.
=IF( ISDATE([Lease Expiration]@row), ROUND((NETDAYS(TODAY(), [Lease Expiration]@row) / 365) * 12), "N/A")
I guess you could also use this as well
=IFERROR(ROUND((NETDAYS(TODAY(), [Lease Expiration]@row) / 365) * 12), "N/A")
but I don't like using an Error function as part of planned code
Brent C. Wilson, P.Eng, PMP, Prince2
Facilityy Professional Services Inc.
http://www.facilityy.com
-
@Carmenlita Ashbourne .. Sort of ;-)
If you are looking at using IF statements you might want to look here
They take the function..
IF( logical_expression, value_if_true [ value_if_false ])
So what I wrote in the formula was "IF the Lease expiration contains a date then use Camenlita's formula otherwise put "N/A"
So for status formulas, it really comes down to your LOGICAL_EXPRESSION which is like the question
So for a status, you may want to look at the functions ISBLANK or ISTEXT
So something like
=IF (ISBLANK(Status@row),"Missing Status","Status is Good")
This can be flipped with NOT
=IF(NOT(ISBLANK(Status@row)),"Status is Good","Missing Status")
Also, Smartsheet has a really good Smartsheet Formula Template which goes through all the different types of formulas.. you can play with it and break it.. so don't worry.. have a look for it in the templates area.
Brent C. Wilson, P.Eng, PMP, Prince2
Facilityy Professional Services Inc.
http://www.facilityy.com
Answers
-
This should do the trick.
=IF( ISDATE([Lease Expiration]@row), ROUND((NETDAYS(TODAY(), [Lease Expiration]@row) / 365) * 12), "N/A")
I guess you could also use this as well
=IFERROR(ROUND((NETDAYS(TODAY(), [Lease Expiration]@row) / 365) * 12), "N/A")
but I don't like using an Error function as part of planned code
Brent C. Wilson, P.Eng, PMP, Prince2
Facilityy Professional Services Inc.
http://www.facilityy.com
-
Awesome it worked, thank you so much! Will this work on status formulas as well?
-
@Carmenlita Ashbourne .. Sort of ;-)
If you are looking at using IF statements you might want to look here
They take the function..
IF( logical_expression, value_if_true [ value_if_false ])
So what I wrote in the formula was "IF the Lease expiration contains a date then use Camenlita's formula otherwise put "N/A"
So for status formulas, it really comes down to your LOGICAL_EXPRESSION which is like the question
So for a status, you may want to look at the functions ISBLANK or ISTEXT
So something like
=IF (ISBLANK(Status@row),"Missing Status","Status is Good")
This can be flipped with NOT
=IF(NOT(ISBLANK(Status@row)),"Status is Good","Missing Status")
Also, Smartsheet has a really good Smartsheet Formula Template which goes through all the different types of formulas.. you can play with it and break it.. so don't worry.. have a look for it in the templates area.
Brent C. Wilson, P.Eng, PMP, Prince2
Facilityy Professional Services Inc.
http://www.facilityy.com
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.9K Get Help
- 441 Global Discussions
- 139 Industry Talk
- 471 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 68 Community Job Board
- 495 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!