Forum Discussion

asheyashey's avatar
asheyashey
Icon for Helper I rankHelper I
1 year ago
Solved

My X axis date column in weeks

The image is attached.
I'm able to get it in Week "No" (month) format but not able to sort as in show in the above image.
Each WeekNo should be from the start of the day which is Monday.
Please make sure the date spans over multiple years.

Your help will be appreciated and please mention  the dax if youre using that.
Thank you so much.
 

  • Create a Week Start Date (Monday)


    WeekStartDate =
    'Date'[Date] - WEEKDAY('Date'[Date], 2) + 1


    -This ensures every date maps to the Monday of its week.
    -WEEKDAY(..., 2) makes Monday = 1, Sunday = 7

     

    2. Generate a Sortable Week Index Across Years


    WeekIndex =
    YEAR('Date'[WeekStartDate]) * 100 + WEEKNUM('Date'[WeekStartDate], 2)


    - This gives you values like 202401, 202402, etc.
    - Ensures proper chronological sorting across years.

     

    3. Create Display Format: WeekNo (Month)


    WeekLabel =
    "W" & WEEKNUM('Date'[WeekStartDate], 2) & " (" & FORMAT('Date'[WeekStartDate], "MMM") & ")"

     

    - Example: W32 (Aug)

     

    4. Sort the Display Column by WeekIndex


    In Power BI:
    - Go to the WeekLabel column.
    - Use "Sort by Column" → select WeekIndex.

8 Replies

  • Hi asheyashey 

    Adding on to the same concept mentioned by rohit1991 

     

    Have 2 columns

    Week Start = 'Date'[Date] - WEEKDAY('Date'[Date], 2) + 1
    YearWeek = YEAR('Date'[Week Start]) & FORMAT(WEEKNUM('Date'[Week Start], 2), "00")

     
    Within the X Axis use the label:

    Week Label = "Week " & FORMAT(WEEKNUM('Date'[Week Start], 2), "00") & " (" & FORMAT('Date'[Week Start], "mmm dd") & ")"

     
    Make sure to do the sort either in the visual or within the model pane by selecting the column and sort it by the other.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi asheyashey

    I would also take a moment to thank Shahid12523 MohamedFowzan1 , rohit1991 , FBergamaschi  for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
     

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

    Best Regards,
    Harshitha.

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

      Yes, I did find a solution.Thank you everyone for your inputs.

  • Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

     

    Need help uploading data? click here

     

    Want faster answers? click here

  • Hi asheyashey 

     

    You need a unique week column that starts on Monday and also separates years. try this-

    WeekNum = WEEKNUM('Date'[Date], 2)  
    YearWeek = 'Date'[Year] * 100 + 'Date'[WeekNum]

    Use WeekNum on the X-axis and sort it by YearWeek. This will give you the correct week order across years.

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

    Create a Week Start Date (Monday)


    WeekStartDate =
    'Date'[Date] - WEEKDAY('Date'[Date], 2) + 1


    -This ensures every date maps to the Monday of its week.
    -WEEKDAY(..., 2) makes Monday = 1, Sunday = 7

     

    2. Generate a Sortable Week Index Across Years


    WeekIndex =
    YEAR('Date'[WeekStartDate]) * 100 + WEEKNUM('Date'[WeekStartDate], 2)


    - This gives you values like 202401, 202402, etc.
    - Ensures proper chronological sorting across years.

     

    3. Create Display Format: WeekNo (Month)


    WeekLabel =
    "W" & WEEKNUM('Date'[WeekStartDate], 2) & " (" & FORMAT('Date'[WeekStartDate], "MMM") & ")"

     

    - Example: W32 (Aug)

     

    4. Sort the Display Column by WeekIndex


    In Power BI:
    - Go to the WeekLabel column.
    - Use "Sort by Column" → select WeekIndex.

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

      Hey I was getting this error(attached) while sorting with WeekIndex.
      Sorting Weeklabel with WeekStartDate did the work as well.
      Thank you for your reply.