How to mark column with 1 or 0 if the month is in a date
Hi,
I am trying to track whether or not someone has been active in a month based on their Last Login date. I created the formula to mark a cell as 1 if the month is in the Last Login date or 0 if it is not:
=IF(MONTH([Last Login]@row), 1, 0)
But the problem is it gives an #INVALID DATA TYPE error if it hits a blank date. How do I adjust the formula to put a 0 when there is a blank date like the example screenshot?
Thanks!
Best Answer
-
@CLBai You have two ways to make this work. You can either suppress/replace the error message, or you can prevent the error in the first place. Here's how:
To suppress or replace error messages from any formula, wrap it in IFERROR. The syntax is =IFERROR(formula goes here), value to replace the error message with)
=IFERROR(IF(MONTH([Last Login]@row), 1, 0), 0)
The above will replace the error with a zero
To prevent errors from blank date cells, you can use an IF to tell the system to only run the formula if that value is a date, or use AND to make that check part of the logical expression.
=IF(ISDATE([Last Login]@row), IF(MONTH([Last Login]@row), 1, 0), 0)
=IF(AND(ISDATE([Last Login]@row), IF(MONTH([Last Login]@row)), 1, 0)
Regards,
Jeff Reisman
Link: Smartsheet Functions Help Pages Link: Smartsheet Formula Error Messages
If my answer helped solve your issue, please mark it as accepted so that other users can find it later. Thanks!
Answers
-
You would wrap the whole thing in an IFERROR.
=IFERROR(IF(MONTH([Last Login]@row), 1, 0), 0)
-
@CLBai You have two ways to make this work. You can either suppress/replace the error message, or you can prevent the error in the first place. Here's how:
To suppress or replace error messages from any formula, wrap it in IFERROR. The syntax is =IFERROR(formula goes here), value to replace the error message with)
=IFERROR(IF(MONTH([Last Login]@row), 1, 0), 0)
The above will replace the error with a zero
To prevent errors from blank date cells, you can use an IF to tell the system to only run the formula if that value is a date, or use AND to make that check part of the logical expression.
=IF(ISDATE([Last Login]@row), IF(MONTH([Last Login]@row), 1, 0), 0)
=IF(AND(ISDATE([Last Login]@row), IF(MONTH([Last Login]@row)), 1, 0)
Regards,
Jeff Reisman
Link: Smartsheet Functions Help Pages Link: Smartsheet Formula Error Messages
If my answer helped solve your issue, please mark it as accepted so that other users can find it later. Thanks!
-
Perfect! Thank you so much!
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Customer Resources
- 64.8K Get Help
- 434 Global Discussions
- 138 Industry Talk
- 470 Announcements
- 4.9K Ideas & Feature Requests
- 129 Brandfolder
- 148 Just for fun
- 65 Community Job Board
- 486 Show & Tell
- 33 Member Spotlight
- 2 SmartStories
- 300 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!