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
Anonymous
Not applicable

Weekday starting on friday ending on thursday

Hi all,

 

I will have to add a calculated column with weeks starting on friday ending on thursday.

I have a separate date table on which I would want to add this new week table to,

 

Who knows some dax to create this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

So I figured the solution appeared to be an undocumented feature........ Smiley LOL

 

Veilweek (start vrijdag) = WEEKNUM(Datum[Date];15)

 

View solution in original post

14 REPLIES 14
LivioLanzo
Solution Sage
Solution Sage

@Anonymous you calculated column can be calculated like this:

 

 

= MOD( WEEKDAY( [Date], 2 ) - 5, 7 )

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

Hi @LivioLanzo,

 

I think your formula is not right. It gave me the below shown outcomes. It should be like week 1,2,3,4,5,6,7,8,9,10 - 52 but then for weeks starting on friday ending on thursday. 

 

 

Veilweek = MOD(WEEKDAY(Datum[Date]; 2) -5; 7)

 

tempsnip.png

Ok I mustunderstood your requirement. You can do it like this, provided your date table is named Table and you have a Year column:

 

 

 

 

=
VAR PrevFriday =
    [Date]
        - MOD ( WEEKDAY ( [Date], 2 ) - 57 )
VAR FirstDayOfYear =
    DATE ( YEAR ( [Date] )MONTH ( [Date] )1 )
VAR FirstFridayYEar =
    FirstDayOfYear
        - MOD ( WEEKDAY ( FirstDayOfYear2 ) - 57 )
VAR DiffInBeginOfMonth = FirstDayOfYear - FirstFridayYEar
VAR WNum =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        ALLEXCEPT ( 'Table', 'Table'[Year] ),
        'Table'[Date] <= PrevFriday
    )
        + DiffInBeginOfMonth
RETURN
    INT ( WNum / 7 )
        + 1

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

Thanks for the effort, but this formula does not provide the right weeks.

 

Veilweek = 
VAR PrevFriday =
[Date] - MOD(WEEKDAY([Date];2) -5;7)

VAR FirstDayOfYear =
DATE(YEAR([Date]);MONTH([Date]); 1)

VAR FirstFridayYear=
FirstDayOfYear - MOD(WEEKDAY(FirstDayOfYear;2) -5;7)

VAR DiffInBeginOfMonth = FirstDayOfYear - FirstFridayYear
VAR WNum = 
CALCULATE(
COUNTROWS(Datum);
ALLEXCEPT(Datum; Datum[Year]);
Datum[Date] <= PrevFriday
)
+ DiffInBeginOfMonth
RETURN
INT(WNum / 7 )
    +1

I believe the formula should be the exact same as the following formula in Excel:

=WEEKNUM(date; 15)

 

Unfortunately this formula does not work in DAX....

You are right. I made a small mistake in my formula in the variable:

 

VAR FirstDayOfYear = DATE( YEAR( [Date] ), month( [Date] ), 1 )

 

It should be (as the name suggests 😞

 

VAR FirstDayOfYear = DATE( YEAR( [Date] ), 1, 1 )

 

Hence the final formula is:

 

 

 

=
VAR PrevFriday =
    'Calendar'[Date]
        - MOD ( WEEKDAY ( 'Calendar'[Date], 2 ) - 57 )
VAR FirstDayOfYear =
    DATE ( YEAR ( 'Calendar'[Date] )11 )
VAR FirstFridayYEar =
    FirstDayOfYear
        - MOD ( WEEKDAY ( FirstDayOfYear2 ) - 57 )
VAR DiffInBeginOfMonth = FirstDayOfYear - FirstFridayYEar
VAR WNum =
    CALCULATE (
        COUNTROWS ( 'Calendar' ),
        ALLEXCEPT ( 'Calendar', 'Calendar'[Year] ),
        'Calendar'[Date] <= PrevFriday
    )
        + DiffInBeginOfMonth
RETURN
    INT ( WNum / 7 )
        + 1

 

 

On a side note, if you are pulling data with Power Query, this is much easier to do with Power Query with the following formula =:

 

= Date.WeekOfYear([Date], Day.Friday)

 


 


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


Proud to be a Datanaut!  

I love this formula, but not able to use it if my companies Year starts in October....is there any way to make this work without it going past 52 weeks? 🤣

Anonymous
Not applicable

Hi @LivioLanzo,

 

Unfortunately the formula provides weeks ahead of 52, and continues counting instead of starting over at 1 the next year.

 

So basically the way I want it is as below:

 

 

tempsnip.png

 

 thats in fact the result I am getting

 

 

2018-09-26_16-13-15.jpg2018-09-26_16-12-55.jpg

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

 

Weird, i have reviewed it triple and still leading me to the wrong results...

 

Herebelow the formula Im using,

 

Veilweek = 
VAR PrevFriday =
Datum[Date] - MOD(WEEKDAY(Datum[Date];2) -5;7)

VAR FirstDayOfYear =
DATE(YEAR(Datum[Date]);1;1)

VAR FirstFridayYear=
FirstDayOfYear - MOD(WEEKDAY(FirstDayOfYear;2) -5;7)

VAR DiffInBeginOfMonth = FirstDayOfYear - FirstFridayYear
VAR WNum = 
CALCULATE(
COUNTROWS(Datum);
ALLEXCEPT(Datum; Datum[Year]);
Datum[Date] <= PrevFriday
)
+ DiffInBeginOfMonth
RETURN
INT(WNum / 7 )
    +1

File is here:

 

https://1drv.ms/u/s!AiiWkkwHZChHjwvasKJUoozrTxno

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

Hi @LivioLanzo,

 

Opened the file, copied the same exact formula and still giving me values in weeks of 80 +...

 

Very strange..

 

Would there be another way of solving this?

Can you share your file?

 


 


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


Proud to be a Datanaut!  

Anonymous
Not applicable

So I figured the solution appeared to be an undocumented feature........ Smiley LOL

 

Veilweek (start vrijdag) = WEEKNUM(Datum[Date];15)

 

Anonymous
Not applicable

Super bizzare but very useful. Also works with WEEKDAY. Thanks for finding this!

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.