查找以前的日期

egrigson
egrigson
编辑12/09/19 公式和函数

我为自己创建了一个生产力仪表板ob欧宝娱乐app手机下载,需要找到一个返回前几个月的公式,以便在COUNTIFS语句中引用它们。我有一个公式,它工作得很好,但它不能应付当日期跨越一年的边界,即如果这个月是9月(月8)我的公式将得到8月的统计使用month (TODAY())-1,它返回7(如我所愿)。然而,在一月份,相同的公式返回0,即一月(第1个月)减去1。我怎样才能把12月的票改回12 ?

考虑一下,这也将适用于日期的年份部分,因此我需要一种方法来创建一个公式,该公式采用当前月份(例如2019年1月)并返回上个月,包括相关年份(例如2018年12月)。

谢谢。

标签:

评论

  • 保罗新来的
    保罗新来的 ✭✭✭✭✭✭

    尝试一些类似于……

    今天=月(日期(年(()),月(今天()),1)- 1)

    基本上,你告诉它从当前月的第一天的前一天开始提取月份。

    thinkspi.com

  • 很有创意,谢谢你的快速回答。这对于获取前一个月(和前一年)很有效,但如果我想要返回两个月,三个月等(我报告前六个月)则不起作用。我将尝试在公式中每个月减去28天——由于每个月的天数不同,这个公式最终会失效,但对于6天,它可能会有效,即使不美观。如果有其他建议可以扩展到多个月,那就太好了。

    谢谢,

    艾德

  • 保罗新来的
    保罗新来的 ✭✭✭✭✭✭

    好教育……你没说你想回到六个月前。呃……哈哈厚颜无耻的

    我来试一试,看看能不能弄明白些什么。

    thinkspi.com

  • 保罗新来的
    保罗新来的 ✭✭✭✭✭✭
    编辑01/04/19

    请参见下面的屏幕截图。

    好的。所以我想出了如何引用一个表,根据你想要回溯多少个月,从今天的日期减去每个月的正确天数。下面的公式假设表格在同一张表格上。通过改变数字大胆/下划线,你可以改变你回去的时间。

    =MONTH(TODAY) -SUM(COLLECT([MONTH Days]2:[MONTH Days]25, [MONTH Number]2:[MONTH Number]25, AND(@cell<= INDEX([Month Number]2:[Month Number]25, MATCH(Month (TODAY()), [Month Number]2:[Month Number]25, 0)),@cell>= INDEX([月号]2:[月号]25,MATCH(月号(今天))-6,[月号]2:[月号]25,0)))))))

    基本上,它的作用是参考你今天的月份数字。然后,它减去您想要回溯多少个月(此表只回溯了一年),并确定该数字。然后,它将从[Month days]列中把所有这些天数加起来,再减去今天的日期(这给了您一个合法的日期,可以从中提取月份),然后给出月份的数字。

    如果你想使用一个实际的日期,你有几个选择。要从今天往回看6个月,删除“MONTH”(“从开始和”)“从最后开始。

    如果希望使用引用该月1日的日期,则使用

    =日期(年(公式其余部分不包括月),整个公式,1)

    对于年份,将MONTH替换为year。对于月份,将其保留为month。对于第一个,只需输入1。

    和通知你…这是为非闰年准备的。我还在努力让它区分2月的28和29,如果是闰年的话。我已经在基本公式中得到了它,但将它混合到上面的公式中被证明是一个挑战。

    Capture.PNG

    thinkspi.com

  • 保罗新来的
    保罗新来的 ✭✭✭✭✭✭

    算出闰年的问题了。将其构建到表本身中,以便表将根据今天的日期进行更改,而不是试图比较主公式中的两列…

    在[Month Days]列中,在相应的[Month Number]旁边输入以下公式:

    -10:

    今天())= (((- 1)- (INT(((今天())- 1)/ 4)* 4)= 0,29日,28)

    2:

    今天=如果(一年(())——(INT(年(今天())/ 4)* 4)= 0,29日,28)

    thinkspi.com

  • 谢谢你,保罗,事实证明这比我想象的要长得多,我真的很感谢你在上面那些公式中付出的努力。我想到了另一种方法,即返回给定日期前x个月的日期。

    返回月份数(替换所有四个位置的BOLD数字以更改要返回的月数,在本例中为六个月);

    =如果今天(月((())>6月(日)月(日)日6今天,月(())+ (12 * (INT (ABS(月(今天())6) / 12) + 1) -6))

    返回年份(同样在两个位置替换BOLD中的数字);

    =如果(月(今天())>6今天,年(()),(今天()——(INT (ABS(月(今天())6(1) + (1)

    这样做的好处是不需要查找表,而且它可以工作任何几个月(即你可以回到36个月)。在伪代码中,它是这样工作的;

    如果ADJUST_MONTH < CURRENT_MONTH则//如果查询的月份是今年

    RESULT_MONTH = CURRENT_MONTH - ADJUST_MONTH //简单地减去月份

    RESULT_YEAR = CURRENT_YEAR //年份相同

    其他的

    Year_adjust = (int (abs (current_month - adjust month) / 12)) + 1

    RESULT_MONTH = CURRENT_MONTH + ((12 * YEAR_ADJUST) - ADJUST_MONTH) //计算月份(前一年)

    RESULT_YEAR = CURRENT_YEAR - (YEAR_ADJUST) //计算上一年度

    如果

    完成了!

  • 保罗新来的
    保罗新来的 ✭✭✭✭✭✭

    我喜欢它。你的确实提供了更好的灵活性。我个人要做的唯一调整是使用单元格引用来代替号码。这样我就可以输入数字1而不需要编辑公式。我的手指有时很胖,如果我摸得太多,很容易把东西弄坏。哈哈哈。

    thinkspi.com

  • 这正是我正在做的,但我在上面的公式中保留了一个静态数字,以便于阅读。再次感谢你的帮助。

    艾德。

  • 保罗新来的
    保罗新来的 ✭✭✭✭✭✭

    太棒了!很高兴你找到了解决办法。是的

    thinkspi.com

帮助文章参考资料欧宝体育app官方888

想要直接在智能表中练习使用公式吗?

请查看公式手册模板!
@CamSME<\/a> you'll use join and collect with children or decedents as the range. This video might help.<\/p>
\n \n https:\/\/youtu.be\/Dzo0UYjxMmI\n <\/a>\n<\/div>


<\/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":106286,"type":"question","name":"Health Bubble Turn Colors when Status is Updated","excerpt":"Hello, I am new to Smartsheet. I am trying to get when I change my Status to \"Not Started\" I want the Health bubble to automatically turn grey. And when I change my Status to \"In Progress\" the Health bubble will turn yellow, etc. So far I have: IF(Status1 = \"Not Started\", \"Gray\", \" \"). I want it to change color for each…","categoryID":322,"dateInserted":"2023-06-09T19:29:22+00:00","dateUpdated":"2023-06-09T20:02:36+00:00","dateLastComment":"2023-06-09T21:14:52+00:00","insertUserID":162263,"insertUser":{"userID":162263,"name":"clairehunter","url":"https:\/\/community.smartsheet.com\/profile\/clairehunter","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-06-10T18:54:18+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":162263,"lastUserID":150413,"lastUser":{"userID":150413,"name":"Kleerfyre","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Kleerfyre","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/0FA9VDUULUEH\/n4HMXW6FGST3I.jpg","dateLastActive":"2023-06-09T21:50:34+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":1,"countViews":23,"score":null,"hot":3372684854,"url":"https:\/\/community.smartsheet.com\/discussion\/106286\/health-bubble-turn-colors-when-status-is-updated","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/106286\/health-bubble-turn-colors-when-status-is-updated","format":"Rich","tagIDs":[254,440],"lastPost":{"discussionID":106286,"commentID":379933,"name":"Re: Health Bubble Turn Colors when Status is Updated","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/379933#Comment_379933","dateInserted":"2023-06-09T21:14:52+00:00","insertUserID":150413,"insertUser":{"userID":150413,"name":"Kleerfyre","title":"","url":"https:\/\/community.smartsheet.com\/profile\/Kleerfyre","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/0FA9VDUULUEH\/n4HMXW6FGST3I.jpg","dateLastActive":"2023-06-09T21:50:34+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-06-10T18:54:41+00:00","dateAnswered":"2023-06-09T21:14:52+00:00","acceptedAnswers":[{"commentID":379933,"body":"

You will need a nested IF formula:<\/p>

=IF(Status@row=\"Not Started\", \"Gray\", IF(Status@row=\"In Progress\", \"Yellow\", IF(Status@row=\"Complete\", \"Green\")))<\/p>


<\/p>

Just add more IF Statements like above for what you need. Put all ) at the very end. Then you can turn it into a column formula by right clicking the cell the formula is in and selecting column formula.<\/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"},{"tagID":440,"urlcode":"project-management","name":"Project Management"}]},{"discussionID":106265,"type":"question","name":"If Date is blank + past formula","excerpt":"I can't figure out why this would return a \"yes\" when the date cell is blank. =IF([Date of Site Survey (Product)]@row = \" \", \" \", IF(TODAY() > [Date of Site Survey (Product)]@row, \"yes\", \" \")) Intended logic\/result - If date cell is blank, then \"blank\" (this worked when I tried without the 2nd argument added) If date is in…","categoryID":322,"dateInserted":"2023-06-09T14:00:25+00:00","dateUpdated":null,"dateLastComment":"2023-06-09T23:14:36+00:00","insertUserID":162220,"insertUser":{"userID":162220,"name":"dhawkins","title":"Product Manager","url":"https:\/\/community.smartsheet.com\/profile\/dhawkins","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-06-09T20:05:00+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-06-10T19:07:06+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":31,"score":null,"hot":3372673501,"url":"https:\/\/community.smartsheet.com\/discussion\/106265\/if-date-is-blank-past-formula","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/106265\/if-date-is-blank-past-formula","format":"Rich","lastPost":{"discussionID":106265,"commentID":379953,"name":"Re: If Date is blank + past formula","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/379953#Comment_379953","dateInserted":"2023-06-09T23:14:36+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-06-10T19:07:06+00:00","banned":0,"punished":0,"private":false,"label":"✭✭✭✭✭✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Formulas and Functions","url":"https:\/\/community.smartsheet.com\/categories\/formulas-and-functions"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-06-09T14:28:35+00:00","dateAnswered":"2023-06-09T14:12:11+00:00","acceptedAnswers":[{"commentID":379830,"body":"

Try this:<\/p>

=IF([Date of Site Survey (Product)]@row <> \"//www.santa-greenland.com/community/discussion/38416/\", IF(TODAY() > [Date of Site Survey (Product)]@row, \"yes\", \"no\"))<\/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":[]}],"title":"Trending in Formulas and Functions ","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">

公式和函数趋势