Contact

LibreOffice Calc · Data cleanup · Intermediate

Fix Dates Sorting in the Wrong Order in LibreOffice Calc

Diagnose mixed text and numeric dates, convert ISO date text safely, sort whole records, and reconcile the result without losing the source values.

Worked example tested in LibreOffice Calc 26.8.1.1 · Editorial standards

If Calc sorts dates in the wrong order, test their underlying type with =ISNUMBER(A2). A real spreadsheet date is numeric; text that looks like a date is still text. Convert the text in a helper column, check the interpreted dates, then sort the entire record range by the numeric result.

Changing a cell’s display to Date does not by itself convert date text. Also, TRUE from ISNUMBER proves only that a value is numeric, not that it represents the date you intended.

Before changing an imported table

Keep the original data and work in an ODS copy. These steps follow desktop Calc and LibreOffice 26.8 Help, with English function names and semicolon argument separators. Adapt separators to your formula settings. Avoid trying several regional interpretations on the only copy of the data.

The safe demonstration below deliberately mixes genuine dates and ISO-format text. A CSV cannot preserve that mixed cell-type setup, so enter the formulas and apostrophe-prefixed text exactly as shown.

1. Reproduce and identify mixed types

Set A1:C1 to Date, Order, Amount. Enter these four records:

Row A: Enter exactly B: Order C: Amount
2 =DATE(2026;10;3) O-103 30
3 '2026-10-01 O-101 10
4 =DATE(2026;10;2) O-102 20
5 '2026-09-30 O-093 40

The initial apostrophe tells Calc to store the following characters as text; it is not shown in the cell. Format A2:A5 as Date if desired, but leave the underlying values intact. LibreOffice explains this distinction in Formatting Numbers as Text.

  1. Put Numeric source? in D1.
  2. In D2 enter =ISNUMBER(A2) and fill down through D5.
  3. Expect TRUE, FALSE, TRUE, FALSE in the original row order.
  4. For a before-and-after comparison, copy this sheet through Sheet → Move or Copy Sheet, with Copy enabled, and try sorting the complete A1:D5 range by Date ascending on the copy. Numeric and text values do not become one chronological date sequence merely because they look alike. Return to the unsorted working sheet for conversion.

Do not rely on left/right alignment as the type test; manual formatting can change it. The Sort Criteria documentation distinguishes numeric ordering from text ordering. The exact mixed-type starting order is not the success criterion here; the reconciled chronological order below is.

2. Convert only the text dates

  1. Put Clean date in E1.
  2. Enter this in E2 and fill through E5:
=IF(ISNUMBER(A2);A2;DATEVALUE(A2))
  1. Format E2:E5 using Format → Cells → Numbers → Date. Choose an unambiguous year-month-day display.
  2. In F1 enter Numeric result?; fill F2:F5 with =ISNUMBER(E2) adjusted for each row. All four should be TRUE.
  3. Check the actual day, month and year against the source records, not just the TRUE results.

Select a screenshot to open the full-size image.

The original mixed date types remain in column A while column E contains four cleaned numeric dates and column F shows four TRUE checks.

Native Calc 26.8.1.1 preserves the original values beside the cleaned dates. The formula bar uses the session’s comma separators; adapt the example to your own Formula options.

For a single text value, =DATEVALUE(A3) converts the ISO text 2026-10-01; =YEAR(DATEVALUE(A3)) should return 2026. The DATEVALUE documentation recommends unambiguous ISO notation. The IF branch leaves existing numeric dates intact instead of trying to parse them again.

This helper assumes each nonnumeric input is a valid date string. For real data, leave invalid conversions visible and resolve them before sorting. Do not turn failures into zero dates with IFERROR(...;0).

3. Sort the records, then prove nothing was separated

  1. Confirm the control total =SUM(C2:C5) is 100 and there are four order IDs.
  2. Select A1:F5, including the IDs, amounts and helpers.
  3. Choose Data → Sort. On Sort Criteria, set the first Column to Clean date, select Ascending, check Range contains column labels, and choose Top to bottom (sort rows). All these controls are on Sort Criteria in the tested Calc 26.8.1.1 interface; older interfaces may place some under Options.

Calc Sort Criteria selects Clean date ascending, Range contains column labels, and Top to bottom sort rows.

Keep the column labels out of the sort and move complete rows together. 4. Complete the sort. The header must remain at row 1. 5. Verify this exact sequence by order ID, with its amount still attached:

Clean date Order Amount
2026-09-30 O-093 40
2026-10-01 O-101 10
2026-10-02 O-102 20
2026-10-03 O-103 30

The total must still be 100. Sorting only the date column can detach dates from orders while leaving the total unchanged, so checking the four ID/date/amount pairs is essential.

Keep the raw date column and helper until reconciliation is finished. If you need fixed converted values, copy the clean column to a spare column and use Edit → Paste Special → Paste Special → Values Only. Apply Date format there and recheck it before replacing anything. Values Only preserves results, not formulas; this is documented in Paste Special (Calc). In the native test, E2:E5 was pasted into G2:G5 with Values Only, then formatted as dates. All four fixed dates matched the cleaned dates, and =OR(ISFORMULA(G2);ISFORMULA(G3);ISFORMULA(G4);ISFORMULA(G5)) returned FALSE.

Four sorted records retain their IDs and amounts beside cleaned and fixed dates, with amount total 100 and October record count 3.

The reconciled rows preserve each date, order ID and amount. Fixed dates in column G are values pasted from column E.

Ambiguous dates need a known convention

03/04/2026 could mean March 4 or April 3. Neither sorting nor ISNUMBER can tell you which the source intended. Confirm the export convention first. For file import, select Date (DMY) or Date (MDY) for that field in Text Import, as appropriate; do not guess from your current computer’s locale. See Text Import.

For a known date constructed in a formula, =DATE(2026;10;1) avoids parsing a local date string. DATE is not a strict invalid-date validator: out-of-range month/day arguments can roll into another month. Check the components before using it to repair malformed source data. See DATE.

Use the cleaned dates in calculations

For the four-record example, this should count 3 October records:

=COUNTIFS(E2:E5;">="&DATE(2026;10;1);E2:E5;"<"&DATE(2026;11;1))

For a larger table, use the same pattern with its bounded clean-date range. The next month’s first day is an exclusive upper bound, so genuine numeric timestamps on October 31 are included. See the COUNTIFS date range tutorial and COUNTIFS function.

Timestamp caveat: DATEVALUE discards a time portion. The mixed-type helper retains times already stored numerically but removes them from text timestamps. If time-of-day order matters, use a deliberate date-and-time conversion instead of treating this date-only exercise as a timestamp parser.

Common failures

  • A large integer appears: the result is a serial date; choose a Date display format.
  • DATEVALUE returns #VALUE!: inspect invalid dates, extra characters, the source convention and calculation settings. Do not silently suppress the error.
  • Blank rows become errors or unwanted dates: this example contains no blanks. Exclude blank records or add an explicit blank policy before conversion.
  • Every type check is TRUE but order is still wrong: inspect the parsed month/day, sort direction and selected sort key. A valid but misinterpreted date is still numeric.
  • Dates change when copied from another workbook: check both documents’ date bases. LibreOffice warns about mismatched bases in Move or Copy a Sheet.
  • A product code was mistaken for a date: reimport the original as Text. See prevent CSV date conversion.

Verification: the mixed-type diagnosis, guarded DATEVALUE conversion, whole-record sorting, total 100, October count 3, Values Only copy, and actual save/close/reopen were tested in LibreOffice Calc 26.8.1.1 on Linux (English interface, English USA locale) on 16 October 2026. All four date/ID/amount pairs were reconciled, and the four fixed-date cells were checked to contain no formulas. The screenshots are unchanged native captures; the expected dates and totals were also checked independently. The isolated YEAR example, ambiguous-date import, invalid or blank inputs, text timestamp retention, different date bases, alternate locales and Excel round trips were not tested; those cautions remain documentation-based.