Финансовые кварталы с даты

579
philip kennedy

Я искал другие решения этой проблемы, используя код = ROUNDUP (MONTH (A1) / 3,0).

Однако я не использую стандартные даты для кварталов

Q1 - 02 февраля / 03 мая Q2 - 04 мая / 02 августа Q3 - 03 февраля / 01-ноябрь Q4 - 02 ноября / 31 января

Я знаю, что могу сместить Квартал от значения = ROUNDUP (MONTH (A1) / 3,0), однако это будет 1/2/3-е число месяца в неправильном квартале.

Любая идея, как я могу решить это?

0

1 ответ на вопрос

0
agtoever

The math doesn't get prettier, but what you are actually doing with your quarters is to shift all date's back by a month and then back by the number of days before the first sunday of that month.

So to calculate the number of days in the previous month, we use: =DAY(DATE(YEAR(A1);MONTH(A1);1)-1). This takes the first of this month and subtracts one day and then lets Excel calculate the day-part of that date, which is the number of days in that month.

Next, to shift the number of days back until sunday, we'll subtract a week and add the daynumber of that week, starting with 1 at monday's using: =WEEKDAY(DATE(YEAR(A1);MONTH(A1);1);2)

Finally, after shifting the days, we can compute the quarter just like you suggested: =ROUNDUP(MONTH(A1)/3,0).

Now, if you have a date in A1, you can calculate the "Philip Kennedy"-quarter with (and I'll indent it for clarity):

=ROUNDUP( // Regular "roundup for quarter MONTH( A1- // Take the date, but subtract... DAY(DATE(YEAR(A1);MONTH(A1);1)-1)- // ...the days of last month... 7 + WEEKDAY(DATE(YEAR(A1);MONTH(A1);1);2) // ...and the weekdays before sunday ) / 3;0 )`. 

Or in one line: =ROUNDUP( MONTH(A1-DAY(DATE(YEAR(A1);MONTH(A1);1)-1)-7+WEEKDAY(DATE(YEAR(A1);MONTH(A1);1);2))/3,0)

= НЕДЕЛЯ (МЕСЯЦ (D2-ДЕНЬ (ДАТА (ГОД (D2), МЕСЯЦ (D2), 1) -1) -7 + ДЕНЬНЕД (ДАТА (ГОД (D2), МЕСЯЦ (D2), 1), 2)) / 3,0) Это был 0 вместо 1, но работает отлично, большое спасибо philip kennedy 9 лет назад 0
@philipkennedy: спасибо. Исправил это. agtoever 9 лет назад 0