Forum Discussion

AnnaML's avatar
AnnaML
Frequent Visitor
5 years ago
Solved

Week number not matching date

Hello, 

 

I have an issue with week numbers. I have created a column called YearWeek using the following: 

YearWeek = IF(WEEKNUM([Date].[Date])<10,FORMAT([Date],"YY0WW"),FORMAT([Date],"YYWW"))
 
I put date and yearweek into a table and got the following:
 
 
 

My issues is that the weeks does not match the right dates. For example in this table it shows that week 3 is between 10-16 of January but in reality it's between 17-24 January. I want week 1 to start with January 3rd. 

Can someone please help me? 

 

Thankful for support, 

  • AnnaML 

     

    Try this formula:

     

    YearWeek = RIGHT(IF(WEEKNUM('Calendar'[Date], 21)=53 && MONTH('Calendar'[Date])=1, YEAR('Calendar'[Date]) -1, YEAR('Calendar'[Date])),2) & WEEKNUM('Calendar'[Date], 21)

5 Replies

  • themistoklis's avatar
    themistoklis
    Community Champion

    AnnaML 

     

    If you want to use a Iso YEAR Week the formula should be like this:

    YearWeek = IF(WEEKNUM('Calendar'[Date], 21)=53 && MONTH('Calendar'[Date])=1, YEAR('Calendar'[Date]) -1, YEAR('Calendar'[Date])) & "-" & WEEKNUM('Calendar'[Date], 21)

     

    You need to put another parameter in weeknum function.... the parameter with value 21.

    See also link below:

    https://community.powerbi.com/t5/Desktop/Looking-for-real-year-week/m-p/1591530#M646306

     

     

    • AnnaML's avatar
      AnnaML
      Frequent Visitor

      Hello, 

      Thanks for your answere. It seems to work. Although is it possible to show YYWW instead of YYYY-WW? 

      Kind Regards

      • themistoklis's avatar
        themistoklis
        Community Champion

        AnnaML 

         

        Try this formula:

         

        YearWeek = RIGHT(IF(WEEKNUM('Calendar'[Date], 21)=53 && MONTH('Calendar'[Date])=1, YEAR('Calendar'[Date]) -1, YEAR('Calendar'[Date])),2) & WEEKNUM('Calendar'[Date], 21)

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello, how about if I want the week number only, WW?

    Thank you.