简体   繁体   English

是否有根据条件使用 Google 表格中的公式计算即将到来的日期的公式?

[英]Is there a formula for upcoming date using formula in Google sheet based on condition?

I have a google sheet where I need to get the next upcoming date based on the start date set in column A我有一个谷歌表,我需要根据 A 列中设置的开始日期来获取下一个即将到来的日期

Any pointers are greatly appreciated?任何指针都非常感谢? I am unable exhibit the efforts as I am completely new to this sort of recurrence using Google sheets我无法展示这些努力,因为我对使用 Google 表格的这种重复行为完全陌生

https://docs.google.com/spreadsheets/d/1g_UNg4MjDy3gFufpjZtMRkbBz80K3scQdZOaiAnZi7I/edit#gid=0 https://docs.google.com/spreadsheets/d/1g_UNg4MjDy3gFufpjZtMRkbBz80K3scQdZOaiAnZi7I/edit#gid=0

在此处输入图像描述

This behavior (the next date from today including today) could be implemented manually by this formula:这种行为(从今天开始的下一个日期,包括今天)可以通过这个公式手动实现:

={
  "Next date from today";
  ARRAYFORMULA(
    IFS(
      A2:A >= TODAY(),
        A2:A,
      B2:B = "Daily",
        TODAY() + MOD(TODAY() - A2:A, C2:C),
      B2:B = "Weekly",
        TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
      B2:B = "Monthly",
        EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
      True,
        ""
    )
  )
}

For additional options (like "every 2nd monday of the month" and others) additional options should be implemented in that IFS part.对于其他选项(例如“每月的第二个星期一”等),应在该IFS部分实施其他选项。

在此处输入图像描述

If you are interested in a trivial case where the next date from the start date (column F:F on the screenshot) is needed, then the formula would be much simpler:如果您对需要从开始日期开始的下一个日期(屏幕截图上的F:F列)的简单情况感兴趣,那么公式会简单得多:

={
  "Next date";
  ARRAYFORMULA(
    IFS(
      B2:B = "Daily",
        A2:A + C2:C,
      B2:B = "Weekly",
        A2:A + 7 * C2:C,
      B2:B = "Monthly",
        EDATE(A2:A, C2:C),
      True,
        ""
    )
  )
}

Again, for additional options you'll need to add corresponding part to the IFS .同样,对于其他选项,您需要将相应的部分添加到IFS

You could use IFS to check Frequency , and:您可以使用IFS检查Frequency ,并且:

  • If Daily , add Count value to start date.如果Daily ,将Count值添加到开始日期。
  • If Weekly , add Count value multiplied by 7.如果是Weekly ,则添加Count值乘以 7。
  • If Monthly , since not all months have the same duration, retrieve the YEAR , MONTH and DAY indexes, add Count to the MONTH index, and set a new DATE , EDIT : or as suggested by kishkin , use EDATE .如果是Monthly ,因为并非所有月份都具有相同的持续时间,请检索YEARMONTHDAY索引,将Count添加到MONTH索引,并设置一个新的DATEEDIT :或按照kishkin的建议,使用EDATE

It could be something like this:它可能是这样的:

=ARRAYFORMULA(IFNA(IFS(
    B2:B = "Daily", A2:A + C2:C,
    B2:B = "Weekly", A2:A + 7 * C2:C,
    B2:B = "Monthly", EDATE(A2:A,C2:C)
)))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM