Modifying a date based on 2 variables

Hello Everyone!

I would like to create a formula that says

If the value in the "Variable" column is "HIGH" AND the date in "Column 1" has a year less than today's year, return that date with TODAY"S year. Otherwise return that date unchanged.

In other words, dates in the previous years are brought to this year, dates in this year or future years remain unchanged.

The result would look like this (with "Goal Column" being where the formula is)

image.png

I have gotten this far:

IF(AND([Variable]@row = "High",magic happens here to look at just the year in First Column).DATE(YEAR(TODAY()), MONTH([First Column]@row), DAY([First Column]@row, [First Column]@row)))

(I know I am missing some parentheses in the example, I can fix those. I am looking for the magic sauce in the middle)


Thank you very much for taking a look.

Best Answer

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭
    edited 06/09/23 Answer ✓

    Sure, here is how it breaks down:

    =IF([Variable]@row <> "High", ""

    <> is a way of saying "not equal to". So, in this case, we are saying "Do the following thing if [Variable] is not equal to "High". The double quotes, "", is another way of saying "blank". So if our formula sees that [Variable] contains anything other than "High", it is going to set [Goal Column] as blank.

    IF(YEAR(TODAY()) > YEAR([First Column]@row), DATE(YEAR(TODAY()), MONTH([First Column]@row), DAY([First Column]@row)), [First Column]@row))

    This section of the formula applies to the "else" part of the original IF statement. The first part looked for [Variable] not equal to "High", so this part will apply to [Variable] that does equal "High". First, we are asking whether today's year, YEAR(TODAY(), is greater than the year of [First Column], YEAR([First Column]). If it is, we are going to build a date using the present year, combined with the month and day from [First Column], DATE(YEAR(TODAY()), MONTH([First Column]@row), DAY([First Column]@row)).

    [First Column]@row

    Lastly, if the current year is not greater than [First Column], i.e., they are the same, then we are simply going to set [Goal Column] to the same value as [First Column].

Answers

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭

    =IF(AND([Variable]@row = "High", YEAR(TODAY()) = IFERROR(YEAR([First Column]@row), 0) + 1), DATE(YEAR([First Column]@row) + 1, MONTH([First Column]@row), DAY([First Column]@row)), "")


    This should take care of it. I included an IFERROR to keep things from getting ugly in the event someone forgets to enter a date in [First Column].

  • Hi Carson, thank you for taking the time to help.

    I put this in my sheet and am getting and #INCORRECT ARGUMENT error. Maybe too many references back to First Column is confusing it?

    As a side note, I would not need the IFERROR as the date in "First Column" column is autogenerated and will not ever be blank.

    Much obliged,

    C

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭

    I have it working in a test sheet of my own and copy/pasted the formula back out of my previous comment to be certain there wasn't a typo and it still works. Are [First Column] and [Goal Column] both formatted as dates? I don't believe an error there would throw this specific error, but it never hurts to check.

  • Thank you for the speedy reply!

    Yes, the columns are formatted as DATE.

    I copy/pasted your formula into my sheet and corrected for column names.

    我不再把无效的参数ror, but now I get no returns at all on any row.


    THanks,

    C

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭

    I looked back over your initial question and I definitely misinterpreted what you were asking. Try this:

    =IF([Variable]@row <> "High", "", IF(YEAR(TODAY()) > YEAR([First Column]@row), DATE(YEAR(TODAY()), MONTH([First Column]@row), DAY([First Column]@row)), [First Column]@row))

  • Would you be able to write a narrative of what your new formula is doing?

    I am looking for 2 things:

    1) Look for variable "High"

    2) Then check the year and correct to current year only if it is the past, otherwise leave it unchanged

    I don't see an "AND" in your formula so I am not sure both items have been accounted for.


    To add context, I will have a separate column where I will be doing the same manipulation of the date when the variable is not "High". I was planning on using the same formula (Once I got it worked out) with the first term changed to [Variable]@row <> "High" to accomplish this.

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭
    edited 06/09/23 Answer ✓

    Sure, here is how it breaks down:

    =IF([Variable]@row <> "High", ""

    <> is a way of saying "not equal to". So, in this case, we are saying "Do the following thing if [Variable] is not equal to "High". The double quotes, "", is another way of saying "blank". So if our formula sees that [Variable] contains anything other than "High", it is going to set [Goal Column] as blank.

    IF(YEAR(TODAY()) > YEAR([First Column]@row), DATE(YEAR(TODAY()), MONTH([First Column]@row), DAY([First Column]@row)), [First Column]@row))

    This section of the formula applies to the "else" part of the original IF statement. The first part looked for [Variable] not equal to "High", so this part will apply to [Variable] that does equal "High". First, we are asking whether today's year, YEAR(TODAY(), is greater than the year of [First Column], YEAR([First Column]). If it is, we are going to build a date using the present year, combined with the month and day from [First Column], DATE(YEAR(TODAY()), MONTH([First Column]@row), DAY([First Column]@row)).

    [First Column]@row

    Lastly, if the current year is not greater than [First Column], i.e., they are the same, then we are simply going to set [Goal Column] to the same value as [First Column].

  • All right, great! It seems to be working! YAY!

    AND....

    For my other column where I want to do the same DATE manipulation where the Variable is either Low or Medium, I changed the first term to =IF[Variable]@row="HIGH", "" , and it is working as desired there.

    I very much appreciate your time and patience to explain this.

    Have a great rest of your day and may all your formulas resolve on the first try!

    Carroll

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭

    I'm glad I could help!

Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out theFormula Handbook template!
Hi @Courtney M<\/a>,<\/p>

It's an easy fix - you have an extra comma and bracket at the end of your formula. It should be:<\/p>

=IF([Training Objectives]@row = \"1 - not clear\", 1, IF([Training Objectives]@row = \"2 - somewhat clear\", 2, IF([Training Objectives]@row = \"3 - clear\", 3, IF([Training Objectives]@row = \"4 - very clear\", 4))))<\/p>

Hope this helps!<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":322,"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]},{"discussionID":108909,"type":"question","name":"Calculate # of Incidents Within A Month","excerpt":"I have a sheet that is recording data, we have a field for the date of an incident. I have a Roll Up sheet that is counting the data from the main one, with a number of different items. Is there a way to have a formula that counts the # of rows that have a date in a specific month? I want to be able to pull the number of…","snippet":"I have a sheet that is recording data, we have a field for the date of an incident. I have a Roll Up sheet that is counting the data from the main one, with a number of different…","categoryID":322,"dateInserted":"2023-08-14T14:25:06+00:00","dateUpdated":null,"dateLastComment":"2023-08-14T14:58:55+00:00","insertUserID":154851,"insertUser":{"userID":154851,"name":"Jodi C","url":"https:\/\/community.smartsheet.com\/profile\/Jodi%20C","photoUrl":"https:\/\/aws.smartsheet.com\/storageProxy\/image\/images\/u!1!5qlOufSjfDo!xBtOMYTHJno!KTQ5OLC8XX5","dateLastActive":"2023-08-14T15:05:40+00:00","banned":0,"punished":0,"private":false,"label":"✭✭"},"updateUserID":null,"lastUserID":45516,"lastUser":{"userID":45516,"name":"Paul Newcome","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Paul%20Newcome","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/082\/nQPUTVFKKWDJ2.jpg","dateLastActive":"2023-08-14T14:57:26+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":26,"score":null,"hot":3384050041,"url":"https:\/\/community.smartsheet.com\/discussion\/108909\/calculate-of-incidents-within-a-month","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108909\/calculate-of-incidents-within-a-month","format":"Rich","lastPost":{"discussionID":108909,"commentID":390466,"name":"Re: Calculate # of Incidents Within A Month","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/390466#Comment_390466","dateInserted":"2023-08-14T14:58:55+00:00","insertUserID":45516,"insertUser":{"userID":45516,"name":"Paul Newcome","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Paul%20Newcome","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/082\/nQPUTVFKKWDJ2.jpg","dateLastActive":"2023-08-14T14:57:26+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-14T15:10:17+00:00","dateAnswered":"2023-08-14T14:44:35+00:00","acceptedAnswers":[{"commentID":390460,"body":"

You would use something along the lines of (Jan 2023):<\/p>

=COUNTIFS({Date Column}, AND(IFERROR(MONTH(@cell), 0) = 1<\/strong>, IFERROR(YEAR(@cell), 0) = 2023<\/strong>))<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":322,"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]},{"discussionID":108901,"type":"question","name":"Unique codes","excerpt":"Hey all, I am trying to create a system that will check a unique code that is entered through a form and display if this code has been used already or not. I have a formula in the summary sheet that will asses if the code has been used or not: =VLOOKUP($Code$1, {Z Codes Trial Database Range 1}, 3, 0) The problem is that I…","snippet":"Hey all, I am trying to create a system that will check a unique code that is entered through a form and display if this code has been used already or not. I have a formula in the…","categoryID":322,"dateInserted":"2023-08-14T09:42:01+00:00","dateUpdated":null,"dateLastComment":"2023-08-14T14:37:37+00:00","insertUserID":160845,"insertUser":{"userID":160845,"name":"Itai","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Itai","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/3K032BZUIDXO\/nIVF32ENJD2KA.jpeg","dateLastActive":"2023-08-14T14:06:59+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭"},"updateUserID":null,"lastUserID":45516,"lastUser":{"userID":45516,"name":"Paul Newcome","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Paul%20Newcome","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/082\/nQPUTVFKKWDJ2.jpg","dateLastActive":"2023-08-14T14:57:26+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":5,"countViews":45,"score":null,"hot":3384032978,"url":"https:\/\/community.smartsheet.com\/discussion\/108901\/unique-codes","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108901\/unique-codes","format":"Rich","tagIDs":[204,254],"lastPost":{"discussionID":108901,"commentID":390453,"name":"Re: Unique codes","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/390453#Comment_390453","dateInserted":"2023-08-14T14:37:37+00:00","insertUserID":45516,"insertUser":{"userID":45516,"name":"Paul Newcome","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Paul%20Newcome","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/082\/nQPUTVFKKWDJ2.jpg","dateLastActive":"2023-08-14T14:57:26+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions"}],"groupID":null,"statusID":3,"image":{"url":"https:\/\/us.v-cdn.net\/6031209\/uploads\/RGMU4LB8MFBS\/image.png","urlSrcSet":{"10":"","300":"","800":"","1200":"","1600":""},"alt":"image.png"},"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-14T12:23:27+00:00","dateAnswered":"2023-08-14T11:59:02+00:00","acceptedAnswers":[{"commentID":390433,"body":"

Try nesting in an INDEX function with a specified row of 1.<\/p>

=VLOOKUP(INDEX(Code:Code, 1)<\/strong>, {Cross Sheet Reference}, .......)<\/p>"},{"commentID":390435,"body":"

Try using INDEX(Code:Code, 1) instead of $Code$1<\/p>

Note: Also, I would recommend you use INDEX\/MATCH instead of VLOOKUP. Much more reliable.<\/p>


<\/p>

I hope this helps you.<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":322,"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":204,"urlcode":"Forms","name":"Forms"},{"tagID":254,"urlcode":"Formulas","name":"Formulas"}]}],"initialPaging":{"nextURL":"https:\/\/community.smartsheet.com\/api\/v2\/discussions?page=2&categoryID=322&includeChildCategories=1&type%5B0%5D=Question&excludeHiddenCategories=1&sort=-hot&limit=3&expand%5B0%5D=all&expand%5B1%5D=-body&expand%5B2%5D=insertUser&expand%5B3%5D=lastUser&status=accepted","prevURL":null,"currentPage":1,"total":10000,"limit":3},"title":"Trending in Formulas and Functions ","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">

Trending in Formulas and Functions