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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Vijay08V
Helper III
Helper III

Need help in DAX - Custom Week Num

Hi,

 

I am trying to write DAX function to get 52 rolling weeks in a year assuming my week starts every Thursday and ends on Wednesday. Need some help on the logics

 

M/D/YWKDAY
1-01-2019Week 1Tuesday
1-02-2019Week 1Wednesday
1-03-2019Week 2Thursday
1-04-2019Week 2Friday
1-05-2019Week 2Saturday
1-06-2019Week 2Sunday
1-07-2019Week 2Monday
1-08-2019Week 2Tuesday
1-09-2019Week 2Wednesday
1-10-2019Week 3Thursday
1-11-2019Week 3Friday
1-12-2019Week 3Saturday
1-13-2019Week 3Sunday
1-14-2019Week 3Monday
1-15-2019Week 3Tuesday
1-16-2019Week 3Wednesday
1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

You need to create a custom calendar

 

 

Date = ADDCOLUMNS(CALENDAR(DATE(2020,1,1),DATE(2023,12,31)),
      "Week Day",WEEKDAY([Date],14), //start of the week is thursday
      "Weeknum" ,WEEKNUM([Date],14),
      "Year" , Year([Date])
      )

 

 

and only then count the sliding weeks of the year,

 

 

rolling weeks = 
VAR _CurrentWeek =
    MAX('Date'[Weeknum])
RETURN
    CALCULATE([total],'Date'[Weeknum]<=_CurrentWeek)

 

 

you can download the file here
https://dropmefiles.com/DJb1i

Screen Capture #216.png

 

 

 

 

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

You need to create a custom calendar

 

 

Date = ADDCOLUMNS(CALENDAR(DATE(2020,1,1),DATE(2023,12,31)),
      "Week Day",WEEKDAY([Date],14), //start of the week is thursday
      "Weeknum" ,WEEKNUM([Date],14),
      "Year" , Year([Date])
      )

 

 

and only then count the sliding weeks of the year,

 

 

rolling weeks = 
VAR _CurrentWeek =
    MAX('Date'[Weeknum])
RETURN
    CALCULATE([total],'Date'[Weeknum]<=_CurrentWeek)

 

 

you can download the file here
https://dropmefiles.com/DJb1i

Screen Capture #216.png

 

 

 

 

Anonymous
Not applicable

Do you have more than one year in the table?

Anonymous
Not applicable

Probably there is a better way, but i would do:

 

FGR1986_0-1673556740758.png

 

where 

 

Weekday = WEEKDAY(Tabla[Date].[Date],2)
 
Weeknum = calculate(count(Tabla[Weekday]),FILTER(Tabla,Tabla[Weekday]=4),FILTER(Tabla,Tabla[Date].[Date]<=EARLIER(Tabla[Date].[Date])))+1
 
Ïn weeknum formula the "=4" it's because your week starts on thursday

Not why sure but this logic was not working for me. I was getting Week nums as attached snapimage.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.