title: Google Sheets How to sort this query by dates?
body: <p>I have this query, that brings the information from some tabs</p>
  
  <pre><code>=QUERY({
  IFERROR(QUERY(General!A2:P,"select 'General',K,G,H,I,J where not G contains 'N/A' label 'General''' ",0),{"","","","","",""});
  IFERROR(QUERY(Salud!A2:P,"select 'Salud',K,G,H,I,J where not G contains 'N/A' label 'Salud''' ",0),{"","","","","",""});
  IFERROR(QUERY(Parejas!A2:P,"select 'Parejas',K,G,H,I,J where not G contains 'N/A' label 'Parejas''' ",0),{"","","","","",""});
  IFERROR(QUERY('Paz Hogar'!A2:P,"select 'Paz Hogar',K,G,H,I,J where not G contains 'N/A' label 'Paz Hogar''' ",0),{"","","","","",""});
  IFERROR(QUERY(Sustento!A2:P,"select 'Sustento',K,G,H,I,J where not G contains 'N/A' label 'Sustento''' ",0),{"","","","","",""});
  IFERROR(QUERY(Hijos!A2:P,"select 'Hijos',K,G,H,I,J where not G contains 'N/A' label 'Hijos''' ",0),{"","","","","",""});
  IFERROR(QUERY(Educacion!A2:P,"select 'Educacion',K,G,H,I,J where not G contains 'N/A' label 'Educacion''' ",0),{"","","","","",""});
  IFERROR(QUERY(Otros!A2:P,"select 'Otros',K,G,H,I,J where not G contains 'N/A' label 'Otros''' ",0),{"","","","","",""});
  IFERROR(QUERY(NA!A2:P,"select 'NA',K,G,H,I,J where not G contains 'N/A' label 'NA''' ",0),{"","","","","",""});
  IFERROR(QUERY(a!A2:P,"select 'a',K,G,H,I,J where not G contains 'N/A' label 'a''' ",0),{"","","","","",""})},
  "select * where Col1 is not null and not Col1 contains 'NA' order by Col3 ",0)
  </code></pre>
  
  <p>My problem is that is not sorting by dates correctly</p>
  
  <p><a href="https://i.stack.imgur.com/xW0J2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xW0J2.png" alt="enter image description here"></a></p>
  
  <p>How can I accomplish this?</p>
  
  <p><a href="https://docs.google.com/spreadsheets/d/1EGo0p2CdqVIZBaSdvvxqZklPc0JHneQgbr1gWqTlAhQ/edit?usp=sharing" rel="nofollow noreferrer">Here is a demo sheet</a></p>
  
  <p>Edit:
  The updated formula works perfect now,
  But im trying to add one more column (E) to the query, and when I add it, im getting error, no Col7
  How can I add Col E in the 4th position of the formula ?
  I have been hours, with no luck ;(</p>
  
  <pre><code> =ARRAYFORMULA(SUBSTITUTE(QUERY(QUERY({QUERY({
   IFERROR(QUERY(General!A2:P,     "select 'General',K,G,H,I,J   where E &lt;&gt; '-'  label 'General'''",   0), {"","","","","",""});
   IFERROR(QUERY(Salud!A2:P,       "select 'Salud',K,G,H,I,J     where E &lt;&gt; '-'  label 'Salud'''",     0), {"","","","","",""});
   IFERROR(QUERY(Parejas!A2:P,     "select 'Parejas',K,G,H,I,J   where E &lt;&gt; '-'  label 'Parejas'''",   0), {"","","","","",""});
   IFERROR(QUERY('Paz Hogar'!A2:P, "select 'Paz Hogar',K,G,H,I,J where E &lt;&gt; '-'  label 'Paz Hogar'''", 0), {"","","","","",""});
   IFERROR(QUERY(Sustento!A2:P,    "select 'Sustento',K,G,H,I,J  where E &lt;&gt; '-'  label 'Sustento'''",  0), {"","","","","",""});
   IFERROR(QUERY(Hijos!A2:P,       "select 'Hijos',K,G,H,I,J     where E &lt;&gt; '-'  label 'Hijos'''",     0), {"","","","","",""});
   IFERROR(QUERY(Educacion!A2:P,   "select 'Educacion',K,G,H,I,J where E &lt;&gt; '-'  label 'Educacion'''", 0), {"","","","","",""});
   IFERROR(QUERY(Otros!A2:P,       "select 'Otros',K,G,H,I,J     where E &lt;&gt; '-'  label 'Otros'''",     0), {"","","","","",""});
   IFERROR(QUERY(NA!A2:P,          "select 'NA',K,G,H,I,J        where E &lt;&gt; '-'  label 'NA'''",        0), {"","","","","",""});
   IFERROR(QUERY(a!A2:P,           "select 'a',K,G,H,I,J         where E &lt;&gt; '-'  label 'a'''",         0), {"","","","","",""})},
   "where Col1 is not null and not Col1 contains 'NA'", 0),
   ARRAYFORMULA(DATE(20&amp;RIGHT(QUERY({
   IFERROR(QUERY(General!A2:P,     "select 'General',K,G,H,I,J   where E &lt;&gt; '-'  label 'General'''",   0), {"","","","","",""});
   IFERROR(QUERY(Salud!A2:P,       "select 'Salud',K,G,H,I,J     where E &lt;&gt; '-'  label 'Salud'''",     0), {"","","","","",""});
   IFERROR(QUERY(Parejas!A2:P,     "select 'Parejas',K,G,H,I,J   where E &lt;&gt; '-'  label 'Parejas'''",   0), {"","","","","",""});
   IFERROR(QUERY('Paz Hogar'!A2:P, "select 'Paz Hogar',K,G,H,I,J where E &lt;&gt; '-'  label 'Paz Hogar'''", 0), {"","","","","",""});
   IFERROR(QUERY(Sustento!A2:P,    "select 'Sustento',K,G,H,I,J  where E &lt;&gt; '-'  label 'Sustento'''",  0), {"","","","","",""});
   IFERROR(QUERY(Hijos!A2:P,       "select 'Hijos',K,G,H,I,J     where E &lt;&gt; '-'  label 'Hijos'''",     0), {"","","","","",""});
   IFERROR(QUERY(Educacion!A2:P,   "select 'Educacion',K,G,H,I,J where E &lt;&gt; '-'  label 'Educacion'''", 0), {"","","","","",""});
   IFERROR(QUERY(Otros!A2:P,       "select 'Otros',K,G,H,I,J     where E &lt;&gt; '-'  label 'Otros'''",     0), {"","","","","",""});
   IFERROR(QUERY(NA!A2:P,          "select 'NA',K,G,H,I,J        where E &lt;&gt; '-'  label 'NA'''",        0), {"","","","","",""});
   IFERROR(QUERY(a!A2:P,           "select 'a',K,G,H,I,J         where E &lt;&gt; '-'  label 'a'''",         0), {"","","","","",""})},
   "select Col3 where Col1 is not null and not Col1 contains 'NA'", 0)
  , 2), MONTH(MID(QUERY({
   IFERROR(QUERY(General!A2:P,     "select 'General',K,G,H,I,J   where E &lt;&gt; '-'  label 'General'''",   0), {"","","","","",""});
   IFERROR(QUERY(Salud!A2:P,       "select 'Salud',K,G,H,I,J     where E &lt;&gt; '-'  label 'Salud'''",     0), {"","","","","",""});
   IFERROR(QUERY(Parejas!A2:P,     "select 'Parejas',K,G,H,I,J   where E &lt;&gt; '-'  label 'Parejas'''",   0), {"","","","","",""});
   IFERROR(QUERY('Paz Hogar'!A2:P, "select 'Paz Hogar',K,G,H,I,J where E &lt;&gt; '-'  label 'Paz Hogar'''", 0), {"","","","","",""});
   IFERROR(QUERY(Sustento!A2:P,    "select 'Sustento',K,G,H,I,J  where E &lt;&gt; '-'  label 'Sustento'''",  0), {"","","","","",""});
   IFERROR(QUERY(Hijos!A2:P,       "select 'Hijos',K,G,H,I,J     where E &lt;&gt; '-'  label 'Hijos'''",     0), {"","","","","",""});
   IFERROR(QUERY(Educacion!A2:P,   "select 'Educacion',K,G,H,I,J where E &lt;&gt; '-'  label 'Educacion'''", 0), {"","","","","",""});
   IFERROR(QUERY(Otros!A2:P,       "select 'Otros',K,G,H,I,J     where E &lt;&gt; '-'  label 'Otros'''",     0), {"","","","","",""});
   IFERROR(QUERY(NA!A2:P,          "select 'NA',K,G,H,I,J        where E &lt;&gt; '-'  label 'NA'''",        0), {"","","","","",""});
   IFERROR(QUERY(a!A2:P,           "select 'a',K,G,H,I,J         where E &lt;&gt; '-'  label 'a'''",         0), {"","","","","",""})},
   "select Col3 where Col1 is not null and not Col1 contains 'NA'", 0), 4, 3)&amp;1), LEFT(QUERY({
   IFERROR(QUERY(General!A2:P,     "select 'General',K,G,H,I,J   where E &lt;&gt; '-'  label 'General'''",   0), {"","","","","",""});
   IFERROR(QUERY(Salud!A2:P,       "select 'Salud',K,G,H,I,J     where E &lt;&gt; '-'  label 'Salud'''",     0), {"","","","","",""});
   IFERROR(QUERY(Parejas!A2:P,     "select 'Parejas',K,G,H,I,J   where E &lt;&gt; '-'  label 'Parejas'''",   0), {"","","","","",""});
   IFERROR(QUERY('Paz Hogar'!A2:P, "select 'Paz Hogar',K,G,H,I,J where E &lt;&gt; '-'  label 'Paz Hogar'''", 0), {"","","","","",""});
   IFERROR(QUERY(Sustento!A2:P,    "select 'Sustento',K,G,H,I,J  where E &lt;&gt; '-'  label 'Sustento'''",  0), {"","","","","",""});
   IFERROR(QUERY(Hijos!A2:P,       "select 'Hijos',K,G,H,I,J     where E &lt;&gt; '-'  label 'Hijos'''",     0), {"","","","","",""});
   IFERROR(QUERY(Educacion!A2:P,   "select 'Educacion',K,G,H,I,J where E &lt;&gt; '-'  label 'Educacion'''", 0), {"","","","","",""});
   IFERROR(QUERY(Otros!A2:P,       "select 'Otros',K,G,H,I,J     where E &lt;&gt; '-'  label 'Otros'''",     0), {"","","","","",""});
   IFERROR(QUERY(NA!A2:P,          "select 'NA',K,G,H,I,J        where E &lt;&gt; '-'  label 'NA'''",        0), {"","","","","",""});
   IFERROR(QUERY(a!A2:P,           "select 'a',K,G,H,I,J         where E &lt;&gt; '-'  label 'a'''",         0), {"","","","","",""})},
   "select Col3 where Col1 is not null and not Col1 contains 'NA'", 0),2)))}, 
   "select Col1,Col2,Col7,Col4,Col5,Col6 order by Col7", 0), 
   "format Col3 'dd-mmm-yy'", 0), "30-Nov-20", ""))
  </code></pre>