Welcome to the Smartsheet Forum Archives


The posts in this forum are no longer monitored for accuracy and their content may no longer be current. If there's a discussion here that interests you and you'd like to find (or create) a more current version, pleaseVisit the Current Forums.

LOOKUP() Function Help

I'm trying to write a function that will determine the county of an address based on the city. So far, I have created a table with several counties forming the vertical axis and then a list of all of the cities in each county running along the horizontal axis. It looks something like this:

County 1 City1 City2 City3

County 2 City4 City5 City6

County 3 City7 City8 City9

County 4 City10 City11 City12

My function looks like this:

=LOOKUP("City8", [County]1:[City]3, 1, false)

My understanding of the formula tells me that this function should search for City8 and then return the corresponding value in the first column of the table. So, it should return "County 3". However, I just get a blank cell.

The only time that I don't get a blank cell is when I search for the county instead of the city. For example:

=查找(“县3”,计数y]1:[City]3, 1, false) returns "County 3"

=查找(“县3”,计数y]1:[City]3, 3, false) returns "City8"

Can anyone help explain what is going wrong with this formula? I've used the LOOKUP() function before and it works just fine in my other sheets.

谢谢!

Tags:

Comments

  • Taylor F
    Taylor F Employee Admin

    Hello John,

    LOOKUP will take the value that you pass it, in this case "city8", and will only look for the value in the first column of the table that you provide it. Then it will return the value that is found in the column number that you provide.

    You will either need to move the cities into the first column and have their counties next to each city and then return the value found in the second column or a combination of MATCH and INDEX to create your own LOOKUP formula.

    =INDEX(County1:County4, IFERROR(MATCH("City 8", [City A]1:[City A]4, 0), 0) + IFERROR(MATCH("City 8", [City B]1:[City B]4, 0), 0) + IFERROR(MATCH("City 8", [City C]1:[City C]4, 0), 0))

    In this formula, each city column is broken up in three parts as there are three columns for the cities.

    IFERROR(MATCH("City 8", [City A]1:[City A]4, 0), 0)

    MATCH will search for "City 8" in the first city column and since it isn't present in the column it will return a #NA RESULT error. We will then use the IFERROR to return an 0 instead of the error. Then we will add the 0 to the next city column which will produce the row number where "City 8" is located. That row number will be passed to the INDEX which will return the county number in the county column.

    Let me know if you have any questions.

  • John Isenhower
    edited 08/12/16

    Taylor,

    Thank you for the response. Your solution makes sense to me.

    However, I simplified the table above. In reality, I have up to 40 cities per county that I need the formula to check. Is there an alternative that will allow me to do this more efficiently, or will I need to write out a 40 part formula?

    谢谢!

  • Taylor F
    Taylor F Employee Admin

    If your table now displays all of the cities in the first column and your counties are in the second, you can simply repeat the counties for each city.

    City 1 County 1

    City 2 County 1

    城市3县1

    City 4 County 2

    City 5 County 2

    City 6 County 2

    Then you can use the LOOKUP function to find the County for each city.

    =LOOKUP('City 4", City1:County40, 2)

    This will dispay the county for City 4 becuase it is check for City 4 in the first column of the table and is returing the value found in the second column of the table.

  • Taylor,

    That's what I ended up doing. I was just looking for a more compact system because I didn't want to create that many more cells since my sheet already has 70 columns.

    Thank you anyways for your help!

  • I'm working with a similar formula except the formula won't autofill when I type in the new row. Also, when I drag the formulas from the row above, my lookup table shifts down a row as well. I need the lookup table to stay the same but the search value should move to match the row. Is this possible?

    It would be better if I could do a lookup table in a different sheet, then my dataset would be all cells.

    注意:我测试make sure it was picking up a pattern in the rows above by coloring those cells, the new row matched the colors but not the formulas.

This discussion has been closed.
Try something like this...<\/p>


<\/p>

Months:<\/p>

=INT([Duration Days]@row \/ 30)<\/p>


<\/p>

Weeks:<\/p>

=INT(([Duration Days]@row - (Months@row * 30)) \/ 7)<\/p>


<\/p>

Days:<\/p>

=[Duration Days]@row - ((Weeks@row * 7) + (Months@row * 30))<\/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":219,"urlcode":"Sheets","name":"Sheets"},{"tagID":254,"urlcode":"Formulas","name":"Formulas"},{"tagID":324,"urlcode":"community-platform","name":"Community Platform"}]},{"discussionID":107883,"type":"question","name":"Moving closed \"tickets\" to a second sheet","excerpt":"I have a sheet where we log our support as it comes in. I have a \"completed\" check box to check once it is finished. It also has a date created field. I setup a second copy of the sheet. On the first sheet I added automation to move any row that is \"completed\" and over 3 days old to the second sheet. This works well.…","snippet":"I have a sheet where we log our support as it comes in. I have a \"completed\" check box to check once it is finished. It also has a date created field. I setup a second copy of the…","categoryID":321,"dateInserted":"2023-07-20T20:03:02+00:00","dateUpdated":null,"dateLastComment":"2023-07-20T20:49:17+00:00","insertUserID":163730,"insertUser":{"userID":163730,"name":"TheoR74","title":"Manager","url":"https:\/\/community.smartsheet.com\/profile\/TheoR74","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-07-20T20:49:49+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":163730,"lastUser":{"userID":163730,"name":"TheoR74","title":"Manager","url":"https:\/\/community.smartsheet.com\/profile\/TheoR74","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-07-20T20:49:49+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":2,"countViews":23,"score":null,"hot":3379770739,"url":"https:\/\/community.smartsheet.com\/discussion\/107883\/moving-closed-tickets-to-a-second-sheet","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/107883\/moving-closed-tickets-to-a-second-sheet","format":"Rich","tagIDs":[334],"lastPost":{"discussionID":107883,"commentID":386291,"name":"Re: Moving closed \"tickets\" to a second sheet","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/386291#Comment_386291","dateInserted":"2023-07-20T20:49:17+00:00","insertUserID":163730,"insertUser":{"userID":163730,"name":"TheoR74","title":"Manager","url":"https:\/\/community.smartsheet.com\/profile\/TheoR74","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-07-20T20:49:49+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":"Smartsheet Basics","url":"https:\/\/community.smartsheet.com\/categories\/smartsheet-basics%2B"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-07-20T20:50:00+00:00","dateAnswered":"2023-07-20T20:14:12+00:00","acceptedAnswers":[{"commentID":386274,"body":"

@TheoR74<\/a>,<\/p>

As long as your destination sheet doesn't have the numbering column setup as an Auto Number, you should be fine. In your destination sheet, keep the numbering column as a \"Text\/Number\" column instead.<\/p>

BRgds,<\/p>

-Ray<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":321,"name":"Smartsheet Basics","url":"https:\/\/community.smartsheet.com\/categories\/smartsheet-basics%2B","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":334,"urlcode":"automations","name":"Automations"}]},{"discussionID":107875,"type":"question","name":"IF Statement with multiple dates an count.","excerpt":"Hello, I have a large sheet that I am trying to calculate several dates to populate dependent on a Count in a row field (ie - a count of 0 would generate a date being pulled from one column, and a count of one generating a date from another column). Columns in Question: \"Was Rejected\" - this is a count on either it has…","snippet":"Hello, I have a large sheet that I am trying to calculate several dates to populate dependent on a Count in a row field (ie - a count of 0 would generate a date being pulled from…","categoryID":322,"dateInserted":"2023-07-20T18:16:53+00:00","dateUpdated":null,"dateLastComment":"2023-07-20T20:15:17+00:00","insertUserID":163694,"insertUser":{"userID":163694,"name":"Jivi3","title":"Project Manager","url":"https:\/\/community.smartsheet.com\/profile\/Jivi3","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-07-20T20:47:46+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-07-20T21:15:47+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":24,"score":null,"hot":3379762930,"url":"https:\/\/community.smartsheet.com\/discussion\/107875\/if-statement-with-multiple-dates-an-count","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/107875\/if-statement-with-multiple-dates-an-count","format":"Rich","tagIDs":[254],"lastPost":{"discussionID":107875,"commentID":386276,"name":"Re: IF Statement with multiple dates an count.","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/386276#Comment_386276","dateInserted":"2023-07-20T20:15:17+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-07-20T21:15:47+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-07-20T20:13:37+00:00","dateAnswered":"2023-07-20T18:21:07+00:00","acceptedAnswers":[{"commentID":386241,"body":"

Make sure all three columns are set as date type columns.<\/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":254,"urlcode":"Formulas","name":"Formulas"}]}],"initialPaging":{"nextURL":"https:\/\/community.smartsheet.com\/api\/v2\/discussions?page=2&includeChildCategories=1&type%5B0%5D=Question&excludeHiddenCategories=1&siteSectionID=0&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 Posts","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">

Trending Posts