Search code examples
dategoogle-sheetsgoogle-sheets-formulasubstitutiongoogle-query-language

How to order dates in descending order when there are multiple years in data set


I have an Integromat app pulling weather data with date-time and adding them to my sheet and then I use that data to make some graphs.

The sheet in question can be found here. The weather data is the Data sheet

The issues are in GraphData!A18, GraphData!A31, and GraphData!A130. If I use

=SORT(QUERY(Data!A:D,"order by A desc limit 366"),1,1)

in GraphData!A130, it excludes data from the year 2022 as my date-time is in the format 12.31.2021 01:36. I can't change how Integromat outputs data. I tried to use Format>Number>Custom date and time but it didn't change anything. So, how do I go about changing the formula to also include 2022 data?


Solution

  • your dates are not valid dates but text strings. to convert them try:

    =INDEX(QUERY({Data!A:D, SUBSTITUTE(Data!A:A, ".", "/")*1}, 
     "select Col1,Col2,Col3,Col4 order by Col5 desc", 1))
    

    enter image description here