Dec 29 2023 04:33 PM
How can I:
Sort by table chronologically by date in MS Excel when some date are DD/MM/YY and some are YYYY only
Dec 29 2023 11:07 PM
Solution
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)
)
Dec 30 2023 02:43 AM
Dec 30 2023 04:51 AM
Dec 30 2023 04:57 AM
Wherever you want the result.
Dec 30 2023 04:57 AM
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?
Dec 30 2023 04:58 AM
Dec 30 2023 05:02 AM
@Lorenzo It is 13 columns of data about sightings of a type of snake. Sometimes dd/mm/yyyy but sometimes yyyy only.
Dec 30 2023 05:18 AM
Dec 30 2023 05:18 AM
Thanks. Couple of questions:
#1 In your [Date] column, when there's only yyyy values are left aligned. Does this mean they are Text values or do simply left aligned the cells?
#2 Given we need to construct a Date value when there's only yyyy, in the result (sorted) do you only want to see yyyy or would 01/01/yyyy be acceptable?
In the meantime, please take a look at how to format as a Table, this will make your life easier
Dec 30 2023 05:22 AM
Dec 30 2023 05:45 AM
Dec 30 2023 05:58 AM
Dec 30 2023 06:06 AM
you mean a pivot table would me more helpful right
Nope. If you open the link I shared earlier it explains how to Format a dataset as a Table, something I've done is the attached workbook in sheet 'data' (table is named Table1). Then on sheet 'DataSorted:
where formula in B3 is:
=LET(
date_col, XMATCH("date",Table1[#Headers]),
array, IF(ISBLANK(Table1), "", Table1),
dates, IF(LEN(Table1[Date]) = 4, DATE(Table1[Date],12,31), Table1[Date]),
repl_dates, HSTACK(
CHOOSECOLS(array, SEQUENCE(,date_col-1)),
dates,
CHOOSECOLS(array, SEQUENCE(,COLUMNS(Table1)-date_col,date_col+1))
),
SORT(repl_dates, date_col)
)
Dec 30 2023 06:08 AM
I think ideally yyyy would be better. This will be used a source data to be imported into MapMate, a biological recording software
This comes a bit late & what difference would this make given you have dd/mm/yyyy values in the [Date] column anyway?
Dec 30 2023 06:15 AM - edited Dec 30 2023 06:18 AM
The attached file is the same as the previous one but it keeps the yyyy values as-is instead of converting them to 31/12/yyyy
Dec 30 2023 06:16 AM
Dec 30 2023 06:21 AM
So with the above formula assuming the dataset is formatted as a Table, the entries can be sorted chronologically?
Yes, see sheet 'DataSorted'
I think the difference would be that saying 31/12/1982 will export an incorrect date into the new software, where as just 1982 is accurate
OK, so see last workbook I shared
Dec 30 2023 06:24 AM
Dec 30 2023 06:36 AM
Dec 29 2023 11:07 PM
Solution
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)
)