title: How to sort multiple columns using QUERY function together with checkboxes
body: <p>I need to sort multiple columns using the QUERY function together with checkboxes which indicate which columns to sort. This should work with multiple columns.</p>
  <p><a href="https://i.stack.imgur.com/GY4iO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GY4iO.png" alt="enter image description here" /></a></p>
  <p>This is the formula:</p>
  <pre><code>=IFERROR(ARRAYFORMULA(
      QUERY(
          {AI4:AY101, TRIM(FLATTEN(QUERY(TRANSPOSE(AJ4:AY101),,9^9)))}, 
          &quot;Select Col1, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16, Col17
          where Col18 is not null
          order by 
          Col&quot;&amp;$P$1&amp;&quot; &quot;&amp;$P$3&amp;&quot;
          &quot;, )),&quot;Loading…&quot;)
  </code></pre>
  <p>It works for single columns if I check only 1 checkbox.
  Is there a way to make it sort multiple columns if I check multiple checkboxes?</p>
  <p>Demo file:<br />
  <a href="https://docs.google.com/spreadsheets/d/1x-IkvUr8hEoBwkKaoZWfdITSf4WXwFCgROpIEwOkaOI/edit" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1x-IkvUr8hEoBwkKaoZWfdITSf4WXwFCgROpIEwOkaOI/edit</a></p>