title: How to calculate column sum
body: <p>I asked this kind of question before, but didn't receive any good answers, perhaps because the code was too long or my question was unclear. For this time I will try to do my best :) So far I've written code to find from a table the row sum, which works fine:</p>
  
  <pre><code>&lt;cfloop list="#product_id_list#" index="product_index"&gt;
      &lt;cfloop list="#month_list#" index="month_index"&gt;
          &lt;cfoutput query="GET_SALES_TOTAL"&gt;
              &lt;cfif AY eq month_index and product_id eq product_index&gt;
                  &lt;cfloop list="#type_index#" index="tt_index"&gt;
                      &lt;cfset 'alan_#tt_index#_#month_index#_#product_index#' = evaluate(tt_index)&gt;
                  &lt;/cfloop&gt;
              &lt;/cfif&gt;
          &lt;/cfoutput&gt;
      &lt;/cfloop&gt;
  &lt;/cfloop&gt;
  &lt;cfset 'total_#ii_index#_#p_index#'=evaluate('total_#ii_index#_#p_index#') + #evaluate('alan_#ii_index#_#ddd_other#_#p_index#')#&gt;
  </code></pre>
  
  <p>Now I want to find a column sum. The code for the column sum works, but incorrectly. It counts the sum of the last product:</p>
  
  <pre><code>&lt;cfloop list="#product_id_list#" index="product_index"&gt;
      &lt;cfloop list="#month_list#" index="month_index"&gt;
          &lt;cfoutput query="GET_SALES_TOTAL"&gt;
              &lt;cfif AY eq month_index and product_id eq product_index&gt;
                  &lt;cfloop list="#type_index#" index="tt_index"&gt;
                      &lt;cfset 'alan2_#tt_index#_#month_index#_#product_index#' = evaluate(tt_index)&gt;
                  &lt;/cfloop&gt;
              &lt;/cfif&gt;
          &lt;/cfoutput&gt;
      &lt;/cfloop&gt;
  &lt;/cfloop&gt;
  &lt;cfset 'total2_#ddd_other#_#p_index#'=evaluate('total2_#ddd_other#_#p_index#') + #evaluate('alan2_#ii_index#_#ddd_other#_#p_index#')#&gt;
  </code></pre>
  
  <p>The output for the row sum:</p>
  
  <pre><code>&lt;cfloop list="#product_id_list#" index="p_index"&gt;
      &lt;cfloop list="#type_index#" index="kk_ind"&gt;
          &lt;td align="center"&gt;
            &lt;font color="##FF0000"&gt;#TLFormat(evaluate('total_#kk_ind#_#p_index#'),0)#&lt;/font&gt;
          &lt;/td&gt; 
      &lt;/cfloop&gt;
  &lt;/cfloop&gt;
  </code></pre>
  
  <p>and the output for column sum:</p>
  
  <pre><code>&lt;cfloop list="#month_list#" index="kk"&gt;
   &lt;td align="center"&gt;
     &lt;cfset satis_oran= evaluate('total2_#kk#_#p_index#')&gt;
       #evaluate(satis_oran)#
   &lt;/td&gt;
  &lt;/cfloop&gt;
  </code></pre>
  
  <p>I know that I didn't loop the column output by product id, because once I loop it, it generates a lot of <code>&lt;td&gt;</code>'s, meaning a lot of irrelevant data. What can be the mistake here? </p>