title: Variable for joining a header value AND/OR a delimeter to ordered values in Google Sheets (1B)
body: <p>In this shared <a href="https://docs.google.com/spreadsheets/d/1Vig4TOZC8oRTlWlaw3Zd6SeTuLo1pGqpl5m1zXQISKA/edit?usp=sharing" rel="nofollow noreferrer">Google Sheet</a> there are values in a range, contactenated in a specified order, how can I maintain the specified order while specifying 2 variables:
  A) when to combine the  &quot;header value&quot; and &quot;cell value&quot; into a header/value pair and
  B) when to add a delimiter</p>
  <p>A header/value pair are displayed with the following equation:</p>
  <pre><code>    =ARRAYFORMULA(TRIM(SUBSTITUTE(TRIM(FLATTEN(QUERY(REGEXREPLACE(SORT(TRANSPOSE(
   IF((A2:D4&lt;&gt;&quot;&quot;)*(REGEXMATCH(A1:D1, &quot;^\d+_&quot;)), &quot;♥&quot;&amp;A1:D1&amp;&quot; &quot;&amp;A2:D4, )), 
   FLATTEN(A1:D1), 1), &quot;\d+_&quot;, ),,9^9))), &quot;♥&quot;, CHAR(10)))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/07UfZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/07UfZ.png" alt="enter image description here" /></a></p>
  <p>All header values with a preceding number are displayed in order in the above image.</p>
  <p><strong>Goals</strong>
  However, as in the following image, there are times when it would be useful to</p>
  <ol>
  <li>Not to include the header value</li>
  </ol>
  <ol start="2">
  <li>add one or more variable delimeters (ie <code>CHAR(10), &quot; , &quot;</code> after the cell value string and other times when it would help to</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/oC3FV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oC3FV.png" alt="enter image description here" /></a></p>
  <p><strong>Possible approach:</strong></p>
  <ol>
  <li><p>In the above image, a number + an underscore ex <code>1_Name</code> (B1 )can represent a parameter to include the header/value pair and a number + tilda <code>4~Math</code> (A1) can represent a parameter to exclude the header value</p>
  </li>
  <li><p>Zero or more delimeter variables (&gt;1 represented by <code>&amp;</code>)can be provided after a pipe to designate the delimiters to include afer the resulting string (value or header/variable pair)</p>
  </li>
  </ol>
  <p>Since the above equation, already adds a <code>CHAR(10)</code> delimiter I believe it would make sense to specify values after a pipe to represent a delimeter variable. As in the image below, this parameter would be inserted into the formula in that space.</p>
  <p><a href="https://i.stack.imgur.com/s0QZW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s0QZW.png" alt="enter image description here" /></a></p>
  <p>For example, in B1 the value after the pipe <code>CHAR(10) &amp; CHAR(10)</code> would add two line spaces. In A1, the value after the pipe <code>&quot;, &quot;</code> would simply add a comma without a new line space.</p>
  <p>The shared sheet is <a href="https://docs.google.com/spreadsheets/d/1Vig4TOZC8oRTlWlaw3Zd6SeTuLo1pGqpl5m1zXQISKA/edit?usp=sharing" rel="nofollow noreferrer">here</a>.</p>