Alice
Alice

Reputation: 41

Is there a way to sort month and year string in google sheet or presto sql?

I have data that looks like this:

campaign_type
marmay2022
janmar2022
mayjul2022

I'm trying to sort it based on the year and the first 3 character according to the month and year.

Upvotes: 1

Views: 113

Answers (2)

JvdV
JvdV

Reputation: 75960

Try:

enter image description here

Formula in C2:

=INDEX(SORT({A2:A4,--("01/"&REPLACE(A2:A4,4,3,"/"))},2,1),0,1)

Upvotes: 2

Harun24hr
Harun24hr

Reputation: 37050

Give a try on below formula-

=QUERY({A1:A3,ArrayFormula(DATEVALUE("01-"&LEFT(A1:A3,3)&"-"&RIGHT(A1:A3,4)))},"select Col1 order by Col2")

enter image description here

Upvotes: 0

Related Questions