Forum Discussion

n5722's avatar
n5722
Icon for Helper I rankHelper I
5 years ago
Solved

Incorrect week number 2020/2021

Hello.

I am quite new to Power BI and I have leveraged a lot of knowledge from this forum so far but now I need help from you guys if possible.

I am currently experiencing a problem where Power BI does not show correct week numbers since we switched from the year 2020 to 2021. This is the current behaviour that I get in terms of week numbers:

 

W01 - starts on 01/01/2021

W02 - starts on 04/01/2021

W03 - starts on 11/01/2021

...

 

While it should be like the following:

 

W01 - starts on 04/01/2021

W02 - starts on 11/01/2021

W03 - starts on 18/01/2021

...

 

Since I am working a lot with relative weeks/months/quarters when visualising things, this is the formula that is used to calculalculate the week number:

 

 

 

= Table.AddColumn( #"Added rDate", "Week", each " W" & Text.PadStart( Number.ToText( Date.WeekOfYear( [Date] ) ), 2, "0" ), type text )

 

 

EDIT: My first day of the week is Monday.

 

Can someone please help me solve this problem? Thank you!

6 Replies

  • n5722 what is your first day of week, read this documentation.

     

    = Table.AddColumn( #"Added rDate", "Week", each " W" & Text.PadStart( Number.ToText( Date.WeekOfYear( [Date], Day.Sunday ) ), 2, "0" ), type text )

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

     

  • n5722 change the M code from Day.Sunday to Day.Monday

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • n5722's avatar
      n5722
      Icon for Helper I rankHelper I

      parry2k 

       

      For 2020 everything was ok. The issue is with the transition towards 2021 where the first 3 days of 2021 should still be part of W53 of 2020 while W01 2021 should start on 04/01


  • Hi, check this: 

    CalendarWeek = ROUNDDOWN(([DateKey]-DATE(year([DateKey]-WEEKDAY([DateKey]-1)+4),1,3)+WEEKDAY(DATE(YEAR([DateKey]-WEEKDAY([DateKey]-1)+4),1,3))+5)/7,0)

    Source: 

    https://powerbiuniversity.com/calendario-completo-dax/