Forum Discussion

bslozano's avatar
bslozano
Frequent Visitor
1 year ago
Solved

Sort MonthYear with Unscheduled

I have a MonthYear column in MonthName Year format. I was able to sort that by creating a different column. Now within the MonthYear column, there are some rows that the values are "Unscheduled". How can I go about sorting this in chronological order and have "Unscheduled" last?

 

This screenshot only shows year 2025, but there are several years in the data or else I could manually give each one of these a value in another sort column. 

 

 

  • Hi bslozano ,

     

    The best option is to have a number for the unschedulled and use a monthyear column so you would get:

    202501 - 2025 January

    202502 - 2025 February

    202503 - 2025 March

    ...

    202513 - 2025 Unschedulled

  • Hi bslozano,

    In your table, add a new calculated column using this DAX:

    SortOrder = 
    IF(
        TableName[MonthYear] = "Unscheduled", 
        999999999, 
        YEAR(DATEVALUE("1 " & TableName[MonthYear])) * 100 + MONTH(DATEVALUE("1 " & TableName[MonthYear]))
    )

    Replace TableName with your table's name.

    For rows where MonthYear is "Unscheduled", the formula assigns a high value (999999999) to place it at the end.

    For other rows, the formula calculates a numeric value based on the Year and Month (e.g., 202501 for January 2025).

2 Replies

  • Hi bslozano ,

     

    The best option is to have a number for the unschedulled and use a monthyear column so you would get:

    202501 - 2025 January

    202502 - 2025 February

    202503 - 2025 March

    ...

    202513 - 2025 Unschedulled

  • Hi bslozano,

    In your table, add a new calculated column using this DAX:

    SortOrder = 
    IF(
        TableName[MonthYear] = "Unscheduled", 
        999999999, 
        YEAR(DATEVALUE("1 " & TableName[MonthYear])) * 100 + MONTH(DATEVALUE("1 " & TableName[MonthYear]))
    )

    Replace TableName with your table's name.

    For rows where MonthYear is "Unscheduled", the formula assigns a high value (999999999) to place it at the end.

    For other rows, the formula calculates a numeric value based on the Year and Month (e.g., 202501 for January 2025).