Countifs statements for date fields that are in the past
Hi there,
I am looking to summarize data from a master sheet for inclusion into a dashboard via a project metrics sheet.
Within the master sheet I have an “Opening Date” that is populated when the opening date is decided.
I want to populate the Dashboard with the number of sites thatHAVEopened each month (past tense).
Here is the formula that I have that works to summarize the openings by month (and year). The problem with this formula is that it also counts the sites that are forecasted to open.
=COUNTIFS({Opening Date}, IFERROR(MONTH(@cell), 0) = 8, {Opening Date}, IFERROR(YEAR(@cell), 0) = 2023)
Here is the formula that works for me to calculate the number of sites that have opened this year in the past.
=COUNTIF({Opening Date}, AND(@cell >= DATE(YEAR(TODAY()), 1, 1), @cell <= TODAY()))
I can not seem to figure out how to put the two together by month.
Thank you for your assistance
Best Answer
-
Paul Newcome ✭✭✭✭✭✭
You don't need any helper columns. All you need to do is add a range/criteria set to your existing monthly COUNTIFS to include the date range being less than today.
=COUNTIFS({Opening Date}, IFERROR(MONTH(@cell), 0) = 8, {Opening Date}, IFERROR(YEAR(@cell), 0) = 2023, {Opening Date}, @cell<= TODAY())
Answers
-
Ramzi ✭✭✭✭
Here's one way to do it. For the purposes of this example, I used the same sheet.
创建两个辅助列在你的源表
- Month with column formula: =MONTH([Opening Date]@row)
- Year with column formula: =YEAR([Opening Date]@row)
在阴影格力汇总表(代表n in this example) list out the months in one column and then in the Count column use this column formula: =IF(AND([Month This Year]@row <> "", MONTH(TODAY()) > [Month This Year]@row, YEAR(TODAY()) = Year@row), COUNTIFS(Month:Month, [Month This Year]@row, Year:Year, YEAR(TODAY())))
You will of course need to modify this to do cross sheet reference.
Smartsheet Solutions Architect
www.adapture.com
-
Hi Ramzi – Thanks!! Your help is very much appreciated.
I have recreated your sheet and the formula works (of course) but when I try to enter into my sheet I get an #INCORRECT ARGUMENT SET error, so I have got something wrong with my cross referencing I am guessing.
In my source sheet I have created the helper columns:
“Helper – Opening Date Month”
“Helper – Opening Date Year”
And in my summary sheet I have added a column called
“Month This Year”
If I update your formula with the cross references, I get this formula.
=IF(AND([Month This Year]@row <> "", MONTH(TODAY()) > [Month This Year]@row, YEAR(TODAY()) = {Helper – Opening Date Year}, COUNTIFS({Helper – Opening Date Month}, [Month This Year]@row, {Helper – Opening Date Year}, YEAR(TODAY()))))
And it returns the #INCORRECT ARGUMENT SET error.
When I look up the error in the Function Glossary, there is a function and an argument that is not lining up, but I can not see it. Are you able to?
Again, I appreciate the assistance.
-
Paul Newcome ✭✭✭✭✭✭
You don't need any helper columns. All you need to do is add a range/criteria set to your existing monthly COUNTIFS to include the date range being less than today.
=COUNTIFS({Opening Date}, IFERROR(MONTH(@cell), 0) = 8, {Opening Date}, IFERROR(YEAR(@cell), 0) = 2023, {Opening Date}, @cell<= TODAY())
-
Hi Paul,
Thank you for this. I have been referencing your solutions since starting Smartsheet almost a year ago. I have a hard time wrapping my head around formulas with dates, and this was no different. Now it seems like an easy solution, but I just can't seem to get there myself. Thanks for doing this in this community, I hope it is still fun for you and you continue for a long while.
Derrick
-
Paul Newcome ✭✭✭✭✭✭
Happy to help.️
It is definitely still fun for me even after almost 6 years of building solutions 40+ hours/week. I use it for my main job, the business I own, as well as many facets of my personal life and still look forward to logging in the next day, and there have been plenty of days where I won't even realize that it is already midnight. Hahaha
Help Article Resources
Categories
Check out theFormula Handbook template!
=IF(AND([Average Score]@row>= 5, [Average Score]@row<= 9), \"Project\", IF(AND([Average Score]@row>= 10, [Average Score]@row<= 15), \"Program\"))<\/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":110985,"type":"question","name":"Dashboard Last Updated Date","excerpt":"I would like to display the last time the dashboard was updated. My approach was adding a date field in the summary data that automatically pulls the last saved date of the sheet. I don't think I can do a formula in the date field type. Any other suggestions?","snippet":"I would like to display the last time the dashboard was updated. My approach was adding a date field in the summary data that automatically pulls the last saved date of the sheet.…","categoryID":322,"dateInserted":"2023-09-29T12:56:38+00:00","dateUpdated":"2023-09-29T23:58:27+00:00","dateLastComment":"2023-09-29T16:19:19+00:00","insertUserID":167704,"insertUser":{"userID":167704,"name":"Jenn Moffett","title":"Director, PMO","url":"https:\/\/community.smartsheet.com\/profile\/Jenn%20Moffett","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-09-29T15:38:19+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":166028,"lastUserID":167704,"lastUser":{"userID":167704,"name":"Jenn Moffett","title":"Director, PMO","url":"https:\/\/community.smartsheet.com\/profile\/Jenn%20Moffett","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-09-29T15:38:19+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":2,"countViews":30,"score":null,"hot":3391997757,"url":"https:\/\/community.smartsheet.com\/discussion\/110985\/dashboard-last-updated-date","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/110985\/dashboard-last-updated-date","format":"Rich","tagIDs":[292,335],"lastPost":{"discussionID":110985,"commentID":397701,"name":"Re: Dashboard Last Updated Date","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/397701#Comment_397701","dateInserted":"2023-09-29T16:19:19+00:00","insertUserID":167704,"insertUser":{"userID":167704,"name":"Jenn Moffett","title":"Director, PMO","url":"https:\/\/community.smartsheet.com\/profile\/Jenn%20Moffett","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-09-29T15:38:19+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-09-29T15:39:37+00:00","dateAnswered":"2023-09-29T14:10:25+00:00","acceptedAnswers":[{"commentID":397662,"body":"