Forum Discussion

Joncho_M's avatar
Joncho_M
Regular Visitor
3 years ago
Solved

Months

I am trying to sort the months chronologically, but I don't have a calendar table or any other date column, just the months. How can I sort them correctly?

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Joncho_M ,

     

    You can create a calculated column to get the month number.

    MonthNumber =
    SWITCH (
        [MES],
        "Enero", 1,
        "Febrero", 2,
        "Marzo", 3,
        "Abril", 4,
        "Mayo", 5,
        "Junio", 6,
        "Julio", 7,
        "Agosto", 8,
        "Septiembre", 9,
        "Octubre", 10,
        "Noviembre", 11,
        "Diciembre", 12
    )
    

    Then in the table visual, put the new column into it and sort by MonthNumber.

    Or you can create a calendar table and get the month name.

    Since I'm the English version of Power BI Desktop, the month names are all in English.

    And then sort the MonthName by the MonthNumber.

    Calendar =
    SUMMARIZE (
        ADDCOLUMNS (
            CALENDAR ( DATE ( 2023, 1, 1 ), DATE ( 2023, 12, 31 ) ),
            "MonthNumber", MONTH ( [Date] ),
            "MonthName", FORMAT ( [Date], "MMMM" )
        ),
        [MonthName],
        [MonthNumber]
    )
    

     

    You can connect the calendar table to your table.

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Joncho_M ,

     

    You can create a calculated column to get the month number.

    MonthNumber =
    SWITCH (
        [MES],
        "Enero", 1,
        "Febrero", 2,
        "Marzo", 3,
        "Abril", 4,
        "Mayo", 5,
        "Junio", 6,
        "Julio", 7,
        "Agosto", 8,
        "Septiembre", 9,
        "Octubre", 10,
        "Noviembre", 11,
        "Diciembre", 12
    )
    

    Then in the table visual, put the new column into it and sort by MonthNumber.

    Or you can create a calendar table and get the month name.

    Since I'm the English version of Power BI Desktop, the month names are all in English.

    And then sort the MonthName by the MonthNumber.

    Calendar =
    SUMMARIZE (
        ADDCOLUMNS (
            CALENDAR ( DATE ( 2023, 1, 1 ), DATE ( 2023, 12, 31 ) ),
            "MonthNumber", MONTH ( [Date] ),
            "MonthName", FORMAT ( [Date], "MMMM" )
        ),
        [MonthName],
        [MonthNumber]
    )
    

     

    You can connect the calendar table to your table.

     

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.