Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Continuous week number with year

Hello everyone,

 

I am new to PowerBI and still learning. I have 1 year worth of data which runs from March 2019 to March 2020 which I need to get a comparison in volume per week.

 

I have this formula to get the week number :

 

Reported Week = WEEKNUM('Reported Date'[Reported Date])
 
The issue is when I am putting it into a visual, it puts the january 2020 week at the beginning of the visual.
 
I tried this formula :
 
Reported Week Year = YEAR('Reported Date'[Reported Date]) & "W" & WEEKNUM('Reported Date'[Reported Date])
 
But X axis type is only at categorical which makes the highest value of the week at the beginning of the visual and lowest at the end.
 
Any suggestions? Thank you so much!

 

  • az38's avatar
    az38
    6 years ago

    Anonymous 

    try

     

    Reported Week Year = 
    var _W = WEEKNUM('Reported Date'[Reported Date])
    RETURN
    YEAR('Reported Date'[Reported Date]) & "W" & IF(_W<10, "0"&_W, _W)

     

     

     

4 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      wow! I did not know that. This is actually an improvement. However, using this solution, it sorts it to what I want but with the year 2020 sorts it as 2020W1, 2020W10, 2020W2, 2020W3, and so on.

       

       

       

      • az38's avatar
        az38
        Icon for Community Champion rankCommunity Champion

        Anonymous 

        try

         

        Reported Week Year = 
        var _W = WEEKNUM('Reported Date'[Reported Date])
        RETURN
        YEAR('Reported Date'[Reported Date]) & "W" & IF(_W<10, "0"&_W, _W)

         

         

         

  • FrankAT's avatar
    FrankAT
    Icon for Community Champion rankCommunity Champion

    Hi,

    1. You have to have a calendar table related to your fact table.
    2. This calendar table should be bounded by the smallest and largest date in the fact table.
    3. Use the weeknum from this bounded calendar table.

    Regards FrankAT