Creating a formula to track number of days but with a catch
So I have been tasked with creating a formula that tracks the number of days an element is "No". However, there are multiple forms submitted each day so I do not want to count the number of times a "No" is selected. It needs to be a formula that counts the consecutive days but then resets to 0 if the element has a "Yes" selected instead.
I know that there will be a COUNTIF(DATE in here but im not sure how to avoid counting the number of entries of "No" instead of the consecutive days.
So based on the screenshot--Element 1 should be 4 days, Element 2 should be 0 days and Element 3 should be 4 days. Essentially once an element receives a "Yes" that means the item is up and running again and the formula should reset to a 0.
Answers
-
Paul Newcome ✭✭✭✭✭✭
You are going to need something like this:
=MAX(0, MAX(COLLECT(Date:Date, [Element 1]:[Element 1], @cell = "Yes")) - MAX(COLLECT(Date:Date, [Element 1]:[Element 1], @cell = "No")))
-
CRUSJ ✭
Hi Paul, Thanks for answering! So I tried this and I am getting #InvalidDataType.
I did break the formula in half to make sure they functioned correctly on their own; they are returning a 0 if all the cells show "No" or "Yes". However, if there is a "No" AND a "Yes" in the column, it shows as #Unparseable.
Here's the formula with its actual Sheet data input:
=MAX(0, MAX(COLLECT([日付 Date]:[日付 Date], [入り口ドアベル E Doorbell]:[入り口ドアベル E Doorbell], @cell = "はい Yes"))) - MAX(0, MAX(COLLECT([日付 Date]:[日付 Date], [入り口ドアベル E Doorbell]:[入り口ドアベル E Doorbell], @cell = "いいえ No")))
Ultimately the formula should be returning a 5 based on the below screenshot because E Doorbell has been at "No" for 5 days in a row
-
Paul Newcome ✭✭✭✭✭✭
Make sure the Date column is set as an actual date type column.
-
CRUSJ ✭
Hi Paul--I checked and the date column is indeed formatted to a date
-
Paul Newcome ✭✭✭✭✭✭
If both date columns are in fact set as date type columns, then double check the data itself to ensure it is date actual dates. How exactly are the dates being entered?
-
CRUSJ ✭
Hi Paul--I have attached a screenshot of the columns that I am working with. The date column is set to an actual date type column. The other two columns are just text/number type. The dates are being entered on the coinciding exactly as they appear here.
In this example, I would want the [Formula Test] column to show a 2 because the [E Doorbell] column has had "No" selected 2 days in a row. I think the complicated part of this is that multiple rows will be submitted per day and I need it to only count 1 "No" per day. And then it needs to reset to 0 if "Yes" is selected.
I'm wondering if there is instead a workflow solution to this? I think this may be too complex for a formula, if not impossible in Smartsheet entirely.
-
Paul Newcome ✭✭✭✭✭✭
我想我看到这个问题。你插入额外的closing parenthesis after "Yes". There should only be two there. Remove one and see if that helps.
-
CRUSJ ✭
Hi Paul,
I had to take a break from this to refocus on some other priorities so I apologize for the late reply. Although you may have been happy to be done with this particular problem! I took that parentheses out but am getting Invalid Operation now. Here is the formula:
=MAX(0, MAX(COLLECT([日付 Date]:[日付 Date], [入り口ドアベル E Doorbell]:[入り口ドアベル E Doorbell], @cell = "はい Yes")) - MAX(0, MAX(COLLECT([日付 Date]:[日付 Date], [入り口ドアベル E Doorbell]:[入り口ドアベル E Doorbell], @cell, ="いいえ No"))))
-
Paul Newcome ✭✭✭✭✭✭
The break may have been just what I needed though. Haha. I think I see the issue now:
=MAX(0, MAX(COLLECT([日付 Date]:[日付 Date], [入り口ドアベル E Doorbell]:[入り口ドアベル E Doorbell], @cell = "はい Yes")) - MAX(COLLECT([日付 Date]:[日付 Date], [入り口ドアベル E Doorbell]:[入り口ドアベル E Doorbell], @cell, ="いいえ No")))
Help Article Resources
Categories
Check out theFormula Handbook template!
{Cross Sheet Reference}<\/p>
<\/p>
with<\/p>
[Column name]:[Column Name]<\/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":112222,"type":"question","name":"Count Days and Durations","excerpt":"I am looking to count days used in my schedule per task. I am set up with start and finish date columns along with a duration column. I am trying to calculate days on site from start date to today, but to stop counting days when finish date is reached.","snippet":"I am looking to count days used in my schedule per task. I am set up with start and finish date columns along with a duration column. I am trying to calculate days on site from…","categoryID":322,"dateInserted":"2023-10-26T17:03:59+00:00","dateUpdated":null,"dateLastComment":"2023-10-27T15:15:39+00:00","insertUserID":164388,"insertUser":{"userID":164388,"name":"Caleb W","title":"Operations Leader","url":"https:\/\/community.smartsheet.com\/profile\/Caleb%20W","photoUrl":"https:\/\/lh3.googleusercontent.com\/a-\/AFdZucpGLwolOKyzvAL1Qwa-C_qqnmxB9j9mfmL4qM8Hnw=s96-c","dateLastActive":"2023-10-27T17:19:12+00:00","banned":0,"punished":0,"private":false,"label":"✭✭"},"updateUserID":null,"lastUserID":113581,"lastUser":{"userID":113581,"name":"Matthew J McAteer","url":"https:\/\/community.smartsheet.com\/profile\/Matthew%20J%20McAteer","photoUrl":"https:\/\/aws.smartsheet.com\/storageProxy\/image\/images\/u!1!zDFUs7dXyHo!7bFXOzNnVPw!fm5dCHPC2D9","dateLastActive":"2023-10-27T16:03:18+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":5,"countViews":39,"score":null,"hot":3396762578,"url":"https:\/\/community.smartsheet.com\/discussion\/112222\/count-days-and-durations","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/112222\/count-days-and-durations","format":"Rich","lastPost":{"discussionID":112222,"commentID":402031,"name":"Re: Count Days and Durations","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/402031#Comment_402031","dateInserted":"2023-10-27T15:15:39+00:00","insertUserID":113581,"insertUser":{"userID":113581,"name":"Matthew J McAteer","url":"https:\/\/community.smartsheet.com\/profile\/Matthew%20J%20McAteer","photoUrl":"https:\/\/aws.smartsheet.com\/storageProxy\/image\/images\/u!1!zDFUs7dXyHo!7bFXOzNnVPw!fm5dCHPC2D9","dateLastActive":"2023-10-27T16:03:18+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\/JDZDOA0P3L7I\/image.png","urlSrcSet":{"10":"https:\/\/us.v-cdn.net\/cdn-cgi\/image\/fit=scale-down,width=10\/https:\/\/us.v-cdn.net\/6031209\/uploads\/JDZDOA0P3L7I\/image.png","300":"https:\/\/us.v-cdn.net\/cdn-cgi\/image\/fit=scale-down,width=300\/https:\/\/us.v-cdn.net\/6031209\/uploads\/JDZDOA0P3L7I\/image.png","800":"https:\/\/us.v-cdn.net\/cdn-cgi\/image\/fit=scale-down,width=800\/https:\/\/us.v-cdn.net\/6031209\/uploads\/JDZDOA0P3L7I\/image.png","1200":"https:\/\/us.v-cdn.net\/cdn-cgi\/image\/fit=scale-down,width=1200\/https:\/\/us.v-cdn.net\/6031209\/uploads\/JDZDOA0P3L7I\/image.png","1600":"https:\/\/us.v-cdn.net\/cdn-cgi\/image\/fit=scale-down,width=1600\/https:\/\/us.v-cdn.net\/6031209\/uploads\/JDZDOA0P3L7I\/image.png"},"alt":"image.png"},"attributes":{"question":{"status":"accepted","dateAccepted":"2023-10-27T17:19:33+00:00","dateAnswered":"2023-10-26T22:22:24+00:00","acceptedAnswers":[{"commentID":401941,"body":"