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.
谢谢!
Comments
-
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.
-
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 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!
-
qgarrett ✭✭
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.
Categories
<\/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":"