CASE(WEEKDAY(DATE(YEAR(TODAY()),MONTH(TODAY()),1)),
2,
IF(DAY(TODAY()) -1 <=6 , 1,
IF(DAY(TODAY()) -1 <=13 , 2,
IF(DAY(TODAY()) -1 <=20 , 3,
IF(DAY(TODAY()) -1 <=27 , 4,
5)))),
3,
IF(DAY(TODAY()) -1 <=5 , 1,
IF(DAY(TODAY()) -1 <=12 , 2,
IF(DAY(TODAY()) -1 <=19 , 3,
IF(DAY(TODAY()) -1 <=26 , 4,
5)))),
4,
IF(DAY(TODAY()) -1 <=4 , 1,
IF(DAY(TODAY()) -1 <=11 , 2,
IF(DAY(TODAY()) -1 <=18 , 3,
IF(DAY(TODAY()) -1 <=25 , 4,
5)))),
5,
IF(DAY(TODAY()) -1 <=3 , 1,
IF(DAY(TODAY()) -1 <=10 , 2,
IF(DAY(TODAY()) -1 <=17 , 3,
IF(DAY(TODAY()) -1 <=24 , 4,
IF(DAY(TODAY()) -1 <=31 , 5,
6))))),
6,
IF(DAY(TODAY()) -1 <=2 , 1,
IF(DAY(TODAY()) -1 <=9 , 2,
IF(DAY(TODAY()) -1 <=16 , 3,
IF(DAY(TODAY()) -1 <=23 , 4,
IF(DAY(TODAY()) -1 <=30 , 5,
6))))),
7,
IF(DAY(TODAY()) -1 <=1 , 1,
IF(DAY(TODAY()) -1 <=8 , 2,
IF(DAY(TODAY()) -1 <=15 , 3,
IF(DAY(TODAY()) -1 <=22 , 4,
IF(DAY(TODAY()) -1 <=29 , 5,
6))))),
IF(DAY(TODAY()) -1 <=0 , 1,
IF(DAY(TODAY()) -1 <=7 , 2,
IF(DAY(TODAY()) -1 <=14 , 3,
IF(DAY(TODAY()) -1 <=21 , 4,
IF(DAY(TODAY()) -1 <=28 , 5,
6)))))
)
考え方
月の1日が何曜日なのかによって、1日と各日の差が各週で最大値が違うことを利用する