How to return most recent value when conditions met. Smartsheet Support is Stumped

BWheel
BWheel
edited 06/13/23 inFormulas and Functions

Hello,

I stumped Smartsheet Support with this formula question:

I want to return the most recent approval status from another column based on common Project ID.

I have four columns:

Created Date - Project ID - Enter Status - Project Approval Status (Where the formula exists)

All the columns are text except for Created Date, which is Date.

My current formula is:

=IF(ISBLANK([Enter Status]@row), VLOOKUP([Project ID]@row, [Project ID]:[Enter Status], 4, false), [Enter Status]@row)

Unfortunately, this returns thefirstinstance of approval status and not thelatestone. I believe the solution involves some combination of MAX and COLLECT... There are some brilliant people in this community. Can any of you see a solution where Smartsheet Support cannot?

Thank you

Best Answer

  • BWheel
    BWheel
    Answer ✓

    Ifinallygot it.

    I added the Max Date (Called "LastDate") as a helper column, with your help on the formula:

    =MAX(COLLECT([Created Date]:[Created Date], [Project ID]:[Project ID], [Project ID]@row, [Pr Ap Sta]:[Pr Ap Sta], <>""))

    Then, under "Project Approval Status", I used INDEX(COLLECT (From another topic Paul answered) to pull the correct status from most current:

    =INDEX(COLLECT([Pr Ap Sta]:[Pr Ap Sta], [Project ID]:[Project ID], [Project ID]@row, [Created Date]:[Created Date], LastDate@row), 1)

    image.png

    And there's my answer. Thank you, Paul!

Answers

  • Paul Newcome
    Paul Newcome ✭✭✭✭✭✭

    Using your formula from your other comment:

    =IF(ISBLANK([Pr Ap Sta]@row),(MAXIFS([Created]:[Created],[Project ID]:[Project ID],[Project ID]@row, [Pr Ap Sta], "<>")), [Pr Ap Sta]@row)


    You would replace the MAXIFS with a MAX/COLLECT.

  • Hi Paul - Changing the formula to the following gives me a "Syntax isn't quite right" error.

    =IF(ISBLANK([Pr Ap Sta]@row), MAX(COLLECT([Created]:[Created], [Project ID]:[Project ID], [Project ID]@row, [Pr Ap Sta], "<>")), [Pr Ap Sta]@row)

    I have double checked my column names for mis-typing and can't find a problem ('Pr Ap Sta' is the same as 'Enter Status' in original question)

  • Carson Penticuff
    Carson Penticuff ✭✭✭✭✭✭
    edited 06/13/23

    "<>"

    Is this correct?

  • 我也认为我的公式不能准确ly return the most recent approval status because the most recent instance of the Project ID is thecurrentrow, which is blank.

    If I create a second column to reference the project ID for rows where enter status is not blank, that might solve the problem.

  • Paul Newcome
    Paul Newcome ✭✭✭✭✭✭

    You need to use a full column reference in the bold portion.

    =IF(ISBLANK([Pr Ap Sta]@row), MAX(COLLECT([Created]:[Created], [Project ID]:[Project ID], [Project ID]@row,[Pr Ap Sta], "<>")), [Pr Ap Sta]@row)


    You would also need to change

    "<>"

    to

    <> ""

  • Thanks Paul. I must be close, but I am getting #INVALID OPERATION for the formula

    =IF(ISBLANK([Pr Ap Sta]@row), MAX(COLLECT([Created Date]:[Created Date], [Project ID]:[Project ID], [Project ID]@row, [Pr Ap Sta]:[Pr Ap Sta] <> "")), [Pr Ap Sta]@row)

  • Paul Newcome
    Paul Newcome ✭✭✭✭✭✭

    You're missing a comma between the last range and criteria set of the COLLECT function.

  • I also tried it with the comma and it wants to return 0. Then, I tried to change out the "Created Date" with an earlier date just for the blank rows - which I could do with a substitution step, but that didn't change the result.

    =IF(ISBLANK([Pr Ap Sta]@row), MAX(COLLECT([Created Date]:[Created Date], [Project ID]:[Project ID], [Project ID]@row, [Pr Ap Sta]:[Pr Ap Sta], <>"")), [Pr Ap Sta]@row)

    image.png


  • Paul Newcome
    Paul Newcome ✭✭✭✭✭✭

    What type of column is your [Created Date] column and how exactly is it being populated?

  • BWheel
    BWheel
    Answer ✓

    Ifinallygot it.

    I added the Max Date (Called "LastDate") as a helper column, with your help on the formula:

    =MAX(COLLECT([Created Date]:[Created Date], [Project ID]:[Project ID], [Project ID]@row, [Pr Ap Sta]:[Pr Ap Sta], <>""))

    Then, under "Project Approval Status", I used INDEX(COLLECT (From another topic Paul answered) to pull the correct status from most current:

    =INDEX(COLLECT([Pr Ap Sta]:[Pr Ap Sta], [Project ID]:[Project ID], [Project ID]@row, [Created Date]:[Created Date], LastDate@row), 1)

    image.png

    And there's my answer. Thank you, Paul!

  • And to answer your previous question - Created date is auto generated date field marking when the row was added. The problem with my original formula, I believe, was that it was trying to return the max date when I wanted the status from a different field.

Help Article Resources

Want to practice working with formulas directly in Smartsheet?

Check out the公式手册模板!
Here's another option:<\/p>

In your sheet, create a third section that adds the results of the first two. It would have the same rows, but the formula for each row would add the cells of section 1 + section 2.<\/p>

Add a helper column called ShowInReport as a Check Box and check all the rows in the third section. <\/p>

Create a report and tell it to show you only Section 3 (where the ShowInReport is true.<\/p>

I hope that makes sense.<\/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":108864,"type":"question","name":"Is there a formula to show as %","excerpt":"What I am trying to do is have my overview brought in automatically each month so it doesn't have to manually be typed in. The struggle I'm having is it wants to bring in as a decimal instead of a %. Below is the formula I am currently using. Is there a way to make it show as % =\"We are at \" + [% closed rate]@row + \"…","snippet":"What I am trying to do is have my overview brought in automatically each month so it doesn't have to manually be typed in. The struggle I'm having is it wants to bring in as a…","categoryID":322,"dateInserted":"2023-08-11T17:22:21+00:00","dateUpdated":null,"dateLastComment":"2023-08-11T19:29:15+00:00","insertUserID":144360,"insertUser":{"userID":144360,"name":"Hollie Green","url":"https:\/\/community.smartsheet.com\/profile\/Hollie%20Green","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T20:24:30+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭"},"updateUserID":null,"lastUserID":144360,"lastUser":{"userID":144360,"name":"Hollie Green","url":"https:\/\/community.smartsheet.com\/profile\/Hollie%20Green","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T20:24:30+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":45,"score":null,"hot":3383558496,"url":"https:\/\/community.smartsheet.com\/discussion\/108864\/is-there-a-formula-to-show-as","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108864\/is-there-a-formula-to-show-as","format":"Rich","lastPost":{"discussionID":108864,"commentID":390301,"name":"Re: Is there a formula to show as %","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/390301#Comment_390301","dateInserted":"2023-08-11T19:29:15+00:00","insertUserID":144360,"insertUser":{"userID":144360,"name":"Hollie Green","url":"https:\/\/community.smartsheet.com\/profile\/Hollie%20Green","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T20:24:30+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-11T19:29:56+00:00","dateAnswered":"2023-08-11T17:49:58+00:00","acceptedAnswers":[{"commentID":390269,"body":"

Try this - =\"We are at \" + [% closed rate]@row * 100 + \"% closed rate on ticket status for the month of \"+[Month]@row.<\/p>"},{"commentID":390301,"body":"

I figured it out! Updated formula to get the 2 decimal places as well.<\/p>

=\"We are at \" + IFERROR(ROUND([% closed rate]@row * 100, 2), \"//m.santa-greenland.com/community/discussion/106373/\") + \"% closed rate on ticket status for the month of \" + Month@row<\/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":108861,"type":"question","name":"IF\/AND Formula","excerpt":"Formulas are the bane of my existence and I really need to take a class! Today I'm trying to set up a formula to throw a flag when 2 conditions are met. I want a red ball when I have not received an invoice and the invoice due date is within 30 days. I know I'm close since I've gone from \"unparsable\" to \"incorrect…","snippet":"Formulas are the bane of my existence and I really need to take a class! Today I'm trying to set up a formula to throw a flag when 2 conditions are met. I want a red ball when I…","categoryID":322,"dateInserted":"2023-08-11T16:27:44+00:00","dateUpdated":null,"dateLastComment":"2023-08-11T17:49:45+00:00","insertUserID":120231,"insertUser":{"userID":120231,"name":"Pamela Wagner","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Pamela%20Wagner","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T17:47:38+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"updateUserID":null,"lastUserID":120231,"lastUser":{"userID":120231,"name":"Pamela Wagner","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Pamela%20Wagner","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T17:47:38+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":4,"countViews":63,"score":null,"hot":3383549849,"url":"https:\/\/community.smartsheet.com\/discussion\/108861\/if-and-formula","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108861\/if-and-formula","format":"Rich","lastPost":{"discussionID":108861,"commentID":390268,"name":"Re: IF\/AND Formula","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/390268#Comment_390268","dateInserted":"2023-08-11T17:49:45+00:00","insertUserID":120231,"insertUser":{"userID":120231,"name":"Pamela Wagner","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Pamela%20Wagner","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T17:47:38+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-11T17:48:48+00:00","dateAnswered":"2023-08-11T17:12:43+00:00","acceptedAnswers":[{"commentID":390261,"body":"

You were, indeed, very close.<\/p>

=IF([Invoice Received?]@row = 0, IF(AND([Renewal Date]@row >= TODAY(), [Renewal Date]@row <= TODAY(+30)), \"Red\"))<\/p>"},{"commentID":390264,"body":"

\n \n https:\/\/community.smartsheet.com\/discussion\/108861\/if-and-formula\n <\/a>\n<\/div>\n

It looks like you forgot to close out the AND <\/strong>funtion. Try this<\/p>

=IF([Invoice Received?]@row = 0, \"Green\", IF(AND([Renewal Date]@row >= TODAY(0), [Renewal Date]@row <= TODAY(+30)), \"Red\", \"Yellow\"))<\/code><\/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":[]}],"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