Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply

I want to calculate week number of the month ( week 1, week 2, week 3, week 4 & week 5 )

I want to calculate week number of the month ( week 1, week 2, week 3, week 4 & week 5 ). 

I tried using the formula 

Week Num = CONCATENATE("Week-",WEEKNUM('Date'[Date]) - WEEKNUM(DATE(YEAR('Date'[Date]),MONTH('Date'[Date]), 1)) + 1)
but this formula is showing week 6 as well. 
I need only 5 weeks in month and the week starts from Sunday.
 
Please help me in this.
 
Thanks in advance
 
 
1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @vrushabjain510 ,

 

Create 3 columns as below:

Sunday = IF(WEEKDAY('Table'[Date],1)=1,1,BLANK())
rank = 
var _rank=RANKX(FILTER(ALL('Table'),MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Sunday]<>BLANK()),'Table'[Date],,ASC,Dense)
return
IF('Table'[Sunday]<>BLANK(),_rank,BLANK())
weeknum = 
var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Date]<EARLIER('Table'[Date])&&'Table'[Sunday]=1))
Return
IF('Table'[Sunday]=1,"week"&'Table'[rank],
   IF(_maxdate=BLANK(),BLANK(),
      "week"&CALCULATE(MAX('Table'[rank]),FILTER(ALL('Table'),'Table'[Date]=_maxdate))))

And you will see:

v-kelly-msft_0-1621584762985.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi  @vrushabjain510 ,

 

Create 3 columns as below:

Sunday = IF(WEEKDAY('Table'[Date],1)=1,1,BLANK())
rank = 
var _rank=RANKX(FILTER(ALL('Table'),MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Sunday]<>BLANK()),'Table'[Date],,ASC,Dense)
return
IF('Table'[Sunday]<>BLANK(),_rank,BLANK())
weeknum = 
var _maxdate=CALCULATE(MAX('Table'[Date]),FILTER('Table','Table'[Date]<EARLIER('Table'[Date])&&'Table'[Sunday]=1))
Return
IF('Table'[Sunday]=1,"week"&'Table'[rank],
   IF(_maxdate=BLANK(),BLANK(),
      "week"&CALCULATE(MAX('Table'[rank]),FILTER(ALL('Table'),'Table'[Date]=_maxdate))))

And you will see:

v-kelly-msft_0-1621584762985.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Thejeswar
Resident Rockstar
Resident Rockstar

Hi @vrushabjain510 ,

We can get the weekno using a WEEKNUM() function. Ex. given below

 

WEEKNUM(Table_Name[Date],1)
amitchandak
Super User
Super User

@vrushabjain510 , Create columns like

 

month week No = quotient(datediff([eomonth([date],-1)+1,[date],day),7)+1

 

Week name = if([month week No] < 4, "Week " & [month week No] , "Week 4 & Week 5")

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.