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

纵饮孤独 提交于 2020-07-09 06:59:29

问题


I have a google sheet where I need to get the next upcoming date based on the start date set in column 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

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


回答1:


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.

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:

={
  "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.




回答2:


You could use IFS to check Frequency, and:

  • If Daily, add Count value to start date.
  • If Weekly, add Count value multiplied by 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.

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)
)))



来源:https://stackoverflow.com/questions/62374637/is-there-a-formula-for-upcoming-date-using-formula-in-google-sheet-based-on-cond

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!