May 31, 2022 09:46 PM
Hey!
I was trying to group the weeks by the month, so like if I have a Date, I want to get the weeknum in which the date falls WITHIN that specific month only.
Eg. - 1/6/22 - it should show as 1 - since it comes in 1st week of June.
I read up and tried to use the following formula -
MONTH(TODAY(WEEKNUM(NOW())))
However, its giving the output as 6(?!) I think its because its counting 26th May till 2nd June as a week.
Is there any workaround to this please?
Solved! Go to Solution.
Jun 01, 2022 01:37 AM
Hi Mayank, the TODAY()
function doesn’t take any arguments, so the formula of MONTH(TODAY(WEEKNUM(NOW())))
only does the following:
MONTH(TODAY())
and ignores WEEKNUM(NOW())
As a result, you’re getting the output of 6 as, at the time of writing, NOW()
is the first of June, the sixth month of the year.
To achieve what you’re looking for, try the following formula:
WEEKNUM({Date})
-
WEEKNUM(DATETIME_PARSE(YEAR({Date}) & "-" & MONTH({Date}) & "-01", 'YYYY-MM-DD'))
+ 1
May 31, 2022 09:47 PM
Attaching SS for reference-
Jun 01, 2022 01:37 AM
Hi Mayank, the TODAY()
function doesn’t take any arguments, so the formula of MONTH(TODAY(WEEKNUM(NOW())))
only does the following:
MONTH(TODAY())
and ignores WEEKNUM(NOW())
As a result, you’re getting the output of 6 as, at the time of writing, NOW()
is the first of June, the sixth month of the year.
To achieve what you’re looking for, try the following formula:
WEEKNUM({Date})
-
WEEKNUM(DATETIME_PARSE(YEAR({Date}) & "-" & MONTH({Date}) & "-01", 'YYYY-MM-DD'))
+ 1
Jun 02, 2022 10:04 PM
Hey Adam, could you please explain how this worked?
I’m not able to understand.
Jun 02, 2022 10:34 PM
Hi Mayank, it works by finding out the week number of the date value we give it, and then deducting the week number of the first week of the month of said date value
Consider a date value of 5 June
Its week number is 23.
The week number of the first week of the month of June is 23.
We deduct 23 from 23 and since the result is 0 we know it’s the first week of the month
We then add 1 to it purely for display purposes, as having ‘0 week of the month’ isn’t intuitive
Jun 02, 2022 11:44 PM
Thanks for this. Very helpful.