title: Trying to SUM a formula field based on constraints from another field
body: <p>A little background on the report:
  This is a productivity report for our employees working at our business. We determine their productivity based on the duration of the visits with clients. Some of our employees offer group sessions. They charge each client within the group, even though they are only giving, for example, one hour of service, they can bill for 10 hours if there are 10 people in the group. We determine what service they gave by service codes. </p>
  
  <p>So, I have two fields in this formula, a service code field and a duration field. </p>
  
  <p>The duration field is initially a STRING field from the database, even though it only gives number data, so I change it to a numberVar. The service code field is also a string field, and it sometimes does contain characters and numbers. </p>
  
  <p>What I need Crystal Reports to do is take the sum of the duration. However, if the service code is, say, "1000", it must first divide the duration by 3 before summing it. This is where I get caught up. </p>
  
  <p>Here's my code for the duration:</p>
  
  <pre><code>local numbervar num1;
  If GroupName ({billing_tx_charge_detail.v_SERVICE_CODE})="1530" then 
      num1 := ToNumber({billing_tx_charge_detail.v_duration})/3
  else num1 := ToNumber({billing_tx_charge_detail.v_duration})
  </code></pre>
  
  <p>Then I do a separate formula for the sum, named sumDuration:</p>
  
  <pre><code>Sum(@duration)
  </code></pre>
  
  <p>I get the error that this field cannot be summarized. After searching Google for two days I have found that Crystal cannot summarize fields or formulas involving constants. If I simply say:</p>
  
  <pre><code>local numbervar num1;
  num1 := ToNumber({billing_tx_charge_detail.v_duration})
  </code></pre>
  
  <p>then I can summarize @duration. What am I missing? It has to be something simple, but I'm just not seeing it. Is there a way to create a custom function to accomplish what I am trying to get here? Or is it even simpler than that? </p>
  
  <p>One person suggested creating a SQL command in order to do the calculations before the data gets to the report. I am a SQL newb so I had no idea where to even begin with that. </p>