Forum Discussion

CliveHerbert's avatar
CliveHerbert
Copper Contributor
Dec 30, 2023
Solved

Sort by table chronologically in MS Excel when some date are DD/MM/YY and some are YYYY only

How can I:

 

Sort by table chronologically by date in MS Excel when some date are DD/MM/YY and some are YYYY only

27 Replies

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    Hi CliveHerbert 

     

    In the below example, when there's no dd/MM but YYYY only (length=4) the latter is used to construct a Date like 01/01/YYYY:

     

     

    in C2:

    =SORTBY(
      A2:A7,
      IF(LEN(A2:A7) = 4, DATE(A2:A7,1,1), A2:A7)
    )
    • jennifer2112's avatar
      jennifer2112
      Copper Contributor

       

      In Microsoft Excel, you can sort a table chronologically by date even if some dates are in the format DD/MM/YY and some are in YYYY format. Here's how you can do it:

      1. Select the Data Range: Click and drag to select the entire range of data that includes your dates.

      2. Open the Sort Dialog Box: Go to the "Data" tab on the Excel ribbon, then click on "Sort" in the "Sort & Filter" group. This will open the Sort dialog box.

      3. Add a Custom Sort Level: In the Sort dialog box, you should see a list of columns in your data range. Click on "Add Level" to add a new level for sorting.

      4. Choose the Column: In the "Sort by" dropdown for the new level, choose the column that contains your dates.

      5. Select the Custom List: In the "Order" dropdown for the new level, select "Custom List."

      6. Create a Custom List: Click on the "Custom List" button next to the "Order" dropdown. This will open the Custom Lists dialog box.

      7. Enter the Custom List: In the "List entries" box, enter the date formats you have in your data. For example, if you have DD/MM/YY and YYYY, you would enter them in separate lines like this:

        • DD/MM/YY
        • YYYY
      8. Apply the Custom List: Click "Add" to add the custom list to Excel's list of custom sorts, then click "OK" to close the Custom Lists dialog box.

      9. Sort the Data: Back in the Sort dialog box, make sure the "Sort On" dropdown is set to "Values" and the "Order" dropdown is set to "A to Z" (ascending). Click "OK" to apply the sort.

      Excel will now sort your dates chronologically, taking into account both the DD/MM/YY and YYYY formats you've specified in the custom list.

       

      • Lorenzo's avatar
        Lorenzo
        Silver Contributor

        jennifer2112 

        Very much appreciated & well documented. I'm aware of this approach, however this won't do what they expect, except if missed something...

         

        In the attached workbook there's a sample dataset and the expected result. If you can get the expected result with a custom sort, please (re)explain how you do it, you'll probably save their life

    • TKing530's avatar
      TKing530
      Copper Contributor
      Hi I am trying to help Clive Herbert but I don’t understand where to enter the formula
      • Lorenzo's avatar
        Lorenzo
        Silver Contributor

        TKing530 

         

        You enter the formula where you expect to get the result. That being said this won't necessarily help you as I have no idea where your data are stored on your spreadsheet, how many columns you have...

         

        Could you post at leasr picture showing your spreadsheet?

Resources