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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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

 

 

 

 

FGR1986
Frequent Visitor

Do you have more than one year in the table?

FGR1986
Frequent Visitor

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.