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

Time:07-19

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.

CodePudding user response:

Try:

enter image description here

Formula in C2:

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

CodePudding user response:

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

  • Related