Why isn't my Value() function working?
I'm trying to pull the Time out of the Create Date field (Date/Time format). The column has been renamed "Start Date Time" (as you'll see in the formula below).
I have been able to pull the hour using this formula:
=MID([Start Date Time]@row, FIND(":", [Start Date Time]@row) - 2, 2)
For a row that started at 2 PM, it's giving me a 2.
What I can't seem to do is convert that to a number using Value:
=VALUE(MID([Start Date Time]@row, FIND(":", [Start Date Time]@row) - 2, 2))
results in "#Invalid Value"
Strangely though, I can use another cell to create a value formula that references the first one:
=VALUE([Find Time]4)
And that works - (essentially giving me the same number, but right justified and I can go on to use it in a calculation.
(Incidentally: the Value formula works if the hour is 2 characters (e.g. 10 AM), but not if it's a single character - so I'm guessing the space before the 2 has something to do with that, but shouldn't Value take care of that?)
Why the heck can't I do it all in one formula?? (I'm stubbornly trying to get rid of all my helper columns and get a large calculation into a single formula - this is just a piece of it)....
Best Answer
-
Paul Newcome ✭✭✭✭✭✭
If you remove the date, then you can use a LEFT statement to pull the hour.
DATEONLY([Start Date Time]@row)
will reference the date. From there you can use a SUBSTITUTE function to "replace" that with nothing.
=SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), "")
Now all that is left is the time portion of the data. Using a FIND function to locate the colon and subtracting 1 will tell you how many digits are in the hour portion.
FIND(":", text string) - 1
That gives you the number of digits to pull for the LEFT function.
=LEFT(text string, FIND(":", text string) - 1)
Our text string to run this on would be the result of the SUBSTITUTE function, so we just drop that in to get the hours.
=LEFT(SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), ""), FIND(":", SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), "")) - 1)
Then wrap it in the VALUE function to convert it to a number.
=VALUE(LEFT(SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), ""), FIND(":", SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), "")) - 1))
You can also use a nested LEFT(RIGHT(.................)) with a FIND on the space and a FIND on the colon to get the same information and you can also use the FIND "space" and FIND "colon" results within a MID statement as well.
Start the MID
=MID([Start Date Time]@row,
Locate the starting point which is one character past the space
=MID([Start Date Time]@row, FIND(" ", [Start Date Time]@row) + 1,
Then use that same starting location subtracted from the location of the colon to determine how many digits you need.
=MID([Start Date Time]@row, FIND(" ", [Start Date Time]@row) + 1, FIND(":", [Start Date Time]@row) - (FIND(" ", [Start Date Time]@row) + 1))
Then wrap that in your VALUE statement.
=VALUE(MID([Start Date Time]@row, FIND(" ", [Start Date Time]@row) + 1, FIND(":", [Start Date Time]@row) - (FIND(" ", [Start Date Time]@row) + 1)))
Answers
-
L_123 ✭✭✭✭✭✭
It is because of the space. You are grabbing " 2" instead of just "2". You need to use LEN() to figure out how many characters there are and tell the program to grab the appropriate number of characters rather than just having a static 2.
-
MCorbin Overachievers Alumni
I was afraid of that..... I was trying not to make a calculated field more complicated than it already is :-) (There's much more to it than this piece).....
-
Paul Newcome ✭✭✭✭✭✭
If you remove the date, then you can use a LEFT statement to pull the hour.
DATEONLY([Start Date Time]@row)
will reference the date. From there you can use a SUBSTITUTE function to "replace" that with nothing.
=SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), "")
Now all that is left is the time portion of the data. Using a FIND function to locate the colon and subtracting 1 will tell you how many digits are in the hour portion.
FIND(":", text string) - 1
That gives you the number of digits to pull for the LEFT function.
=LEFT(text string, FIND(":", text string) - 1)
Our text string to run this on would be the result of the SUBSTITUTE function, so we just drop that in to get the hours.
=LEFT(SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), ""), FIND(":", SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), "")) - 1)
Then wrap it in the VALUE function to convert it to a number.
=VALUE(LEFT(SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), ""), FIND(":", SUBSTITUTE([Start Date Time]@row, DATEONLY([Start Date Time]@row), "")) - 1))
You can also use a nested LEFT(RIGHT(.................)) with a FIND on the space and a FIND on the colon to get the same information and you can also use the FIND "space" and FIND "colon" results within a MID statement as well.
Start the MID
=MID([Start Date Time]@row,
Locate the starting point which is one character past the space
=MID([Start Date Time]@row, FIND(" ", [Start Date Time]@row) + 1,
Then use that same starting location subtracted from the location of the colon to determine how many digits you need.
=MID([Start Date Time]@row, FIND(" ", [Start Date Time]@row) + 1, FIND(":", [Start Date Time]@row) - (FIND(" ", [Start Date Time]@row) + 1))
Then wrap that in your VALUE statement.
=VALUE(MID([Start Date Time]@row, FIND(" ", [Start Date Time]@row) + 1, FIND(":", [Start Date Time]@row) - (FIND(" ", [Start Date Time]@row) + 1)))
-
MCorbin Overachievers Alumni
@Paul NewcomeYou are my hero! Thank you!
-
Paul Newcome ✭✭✭✭✭✭
@MCorbinHappy to help.️
Something to keep in mind for more complicated setups... Helper columns are your friend. Break things out into smaller sections for testing and troubleshooting and build things out one piece at a time. Use cell references to tie everything together, and if you still REALLY want to cram it all together, you can copy/paste the formulas in place of cell references to help with nesting.
-
MCorbin Overachievers Alumni
That's exactly what I was doing, but that darn Space, which isn't an issue when I used a helper column, gave me grief why I tried to cram it all together.
这只是我固执地试图得到一个星期一ster formula to work
Help Article Resources
Categories
Check out theFormula Handbook template!
Instead of applying the formula to \"Multiselect Text String\" row, did you tried with \"Multiselect Values\" row?<\/p>
=IF(HAS([Multiselect Values]@row, [Component ID]@row), \"MATCH\", \"NO MATCH\")<\/p>
Thank 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":[]},{"discussionID":109493,"type":"question","name":"I am having trouble using \"And\", \"OR\" & \"Countif(s)\" to build a formula.","excerpt":"Hello, I am attempting to come up with a sheet summary formula that counts cells if they meet at least one of 3 different statuses in the same column, AND also meet one of 5 different statuses in a separate column. So using the screenshot I've provided as an example (although it doesn't have 5 different statuses in the…","snippet":"Hello, I am attempting to come up with a sheet summary formula that counts cells if they meet at least one of 3 different statuses in the same column, AND also meet one of 5…","categoryID":322,"dateInserted":"2023-08-25T20:03:21+00:00","dateUpdated":null,"dateLastComment":"2023-08-26T00:34:49+00:00","insertUserID":165710,"insertUser":{"userID":165710,"name":"SmarsheetNewb","url":"https:\/\/community.smartsheet.com\/profile\/SmarsheetNewb","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-26T00:33:27+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":161714,"lastUser":{"userID":161714,"name":"Carson Penticuff","url":"https:\/\/community.smartsheet.com\/profile\/Carson%20Penticuff","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/B0Q390EZX8XK\/nBGT0U1689CN6.jpg","dateLastActive":"2023-08-27T01:32:22+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":23,"score":null,"hot":3386005690,"url":"https:\/\/community.smartsheet.com\/discussion\/109493\/i-am-having-trouble-using-and-or-countif-s-to-build-a-formula","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/109493\/i-am-having-trouble-using-and-or-countif-s-to-build-a-formula","format":"Rich","tagIDs":[254],"lastPost":{"discussionID":109493,"commentID":392692,"name":"Re: I am having trouble using \"And\", \"OR\" & \"Countif(s)\" to build a formula.","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/392692#Comment_392692","dateInserted":"2023-08-26T00:34:49+00:00","insertUserID":161714,"insertUser":{"userID":161714,"name":"Carson Penticuff","url":"https:\/\/community.smartsheet.com\/profile\/Carson%20Penticuff","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/B0Q390EZX8XK\/nBGT0U1689CN6.jpg","dateLastActive":"2023-08-27T01:32:22+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-26T00:33:25+00:00","dateAnswered":"2023-08-25T20:44:12+00:00","acceptedAnswers":[{"commentID":392662,"body":"
Try this:<\/p>
=COUNTIFS([Item Number]:[Item Number], OR(@cell = \"C001\", @cell = \"COO2\", @cell = \"COO3\", @cell = \"COO4\"), [Status]:[Status], OR(@cell = \"Green\", @cell = \"Yellow\", @cell = \"Red\"))<\/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"}]},{"discussionID":109474,"type":"question","name":"Help with date calculation formula","excerpt":"Hello, I'm trying to find a formula that will help me calculate how long an intake took to resolve. The rows I need to be calculated are Date Reported & Resolution Date. If the resolution date is blank I want it to use the current date in the calculation to see how long this issue has gone unresolved. Any help is much…","snippet":"Hello, I'm trying to find a formula that will help me calculate how long an intake took to resolve. The rows I need to be calculated are Date Reported & Resolution Date. If the…","categoryID":322,"dateInserted":"2023-08-25T16:29:39+00:00","dateUpdated":"2023-08-25T16:29:59+00:00","dateLastComment":"2023-08-25T23:01:30+00:00","insertUserID":165688,"insertUser":{"userID":165688,"name":"Nwest","title":"Systems Analyst","url":"https:\/\/community.smartsheet.com\/profile\/Nwest","photoUrl":"https:\/\/aws.smartsheet.com\/storageProxy\/image\/images\/u!1!ukHVZ18ImX4!BcjWAe8S9SY!l7iQo_PZHOx","dateLastActive":"2023-08-25T17:22:30+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":165688,"lastUserID":8888,"lastUser":{"userID":8888,"name":"Andrée Starå","title":"Smartsheet Expert Consultant & Partner | Workflow Consultant \/ CEO @ WORK BOLD","url":"https:\/\/community.smartsheet.com\/profile\/Andr%C3%A9e%20Star%C3%A5","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/0PAU3GBYQLBT\/nXWM7QXGD6464.jpg","dateLastActive":"2023-08-26T17:06:33+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":23,"score":null,"hot":3385987269,"url":"https:\/\/community.smartsheet.com\/discussion\/109474\/help-with-date-calculation-formula","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/109474\/help-with-date-calculation-formula","format":"Rich","tagIDs":[254],"lastPost":{"discussionID":109474,"commentID":392687,"name":"Re: Help with date calculation formula","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/392687#Comment_392687","dateInserted":"2023-08-25T23:01:30+00:00","insertUserID":8888,"insertUser":{"userID":8888,"name":"Andrée Starå","title":"Smartsheet Expert Consultant & Partner | Workflow Consultant \/ CEO @ WORK BOLD","url":"https:\/\/community.smartsheet.com\/profile\/Andr%C3%A9e%20Star%C3%A5","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/0PAU3GBYQLBT\/nXWM7QXGD6464.jpg","dateLastActive":"2023-08-26T17:06:33+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-25T17:04:22+00:00","dateAnswered":"2023-08-25T16:36:59+00:00","acceptedAnswers":[{"commentID":392622,"body":"