Forum Discussion

Uzi2019's avatar
Uzi2019
Community Champion
3 years ago

Sort week column by multiple values in date

Hi Expert,
I have Date, Start Week, End Week, and Week columns. I want to sort my week column based on date or start week column but because of multiple values in date column I cant sort it. 


Can anyone have any idea how to sort column by multiple values in date column???

Thank you in advance. your help would be appreciated.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI Uzi2019 ,

    Try below steps

     

    To sort the Week column in Power BI based on multiple values in the Date column, you can follow these steps:

    1. Select the Week column in your table visualization.
    2. In the "Modeling" tab of the Power BI ribbon, click on the "Sort by Column" button.
    3. In the dialog box that appears, select the Date column from the drop-down list.
    4. Click OK to apply the sort.

    By specifying the Date column as the sort column for the Week column, Power BI will use the values in the Date column to determine the sorting order of the Week column. This way, your Week column will be sorted based on the corresponding dates.

    • Uzi2019's avatar
      Uzi2019
      Community Champion

      That's not an issue. Issue is multiple datas in date column. That's throwing an error while sorting week column by date.

  • Anonymous's avatar
    Anonymous
    Not applicable

     okay, follow below steps

     

    Create a new calculated column in your data model that calculates the minimum or maximum date for each week. For example, if you want to use the minimum date, you can use the following formula:

     

    DAX
     

     

    • MinDate = CALCULATE(MIN('YourTable'[Date]), ALLEXCEPT('YourTable', 'YourTable'[Week]))

      This formula calculates the minimum date within each week, considering only the rows that have the same Week value as the current row.

    • Once you have the new calculated column (e.g., MinDate), go to your table visualization and select the Week column.

    • In the "Modeling" tab of the Power BI ribbon, click on the "Sort ascending" or "Sort descending" button to sort the Week column based on the MinDate column you just created.

       

    •  

    •  

    Uzi2019