title: Is it possible to use IIF within SUM in a C# DataColumn.Expression?
body: <p>This is the expression I'm trying to evaluate:</p>
  
  <pre><code>Sum(IIF(QUALITY&lt;=9.0,1.0,0.0))
  </code></pre>
  
  <p>The problem is that</p>
  
  <pre><code>string expr = "Sum(IIF(QUALITY&lt;=9.0,1.0,0.0))";
  dataTable.Compute(expr, "")
  </code></pre>
  
  <p>throws an error saying</p>
  
  <pre><code>Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier.
  </code></pre>
  
  <p><br>
  The main challenge is that I can't rewrite the expression by hand, since it's coming to my program in a string from an RDL file, so it originally looks like</p>
  
  <pre><code>Sum(IIF(Fields!QUALITY.Value&lt;=9.0,1.0,0.0))
  </code></pre>
  
  <p>and my program needs to automatically convert that into a string that will be a valid expression when passed to <code>dataTable.Compute()</code>. I determined from Microsoft's documentation of the Compute method that C# doesn't like the "Fields!" or ".Value" parts of the syntax, and by removing them I have simpler expressions working fine; for example, these statements both return the expected values:</p>
  
  <pre><code>dataTable.Compute("Sum(QUALITY)");
  dataTable.Compute("Count(QUALITY)");
  </code></pre>
  
  <p><br>
  Is it possible to do what I'm trying to do? I feel like I should just need a slight change in syntax somewhere for it to work, but I haven't been able to find an answer on the internet and it's getting pretty frustrating.</p>
  
  <p>Here are some of the things I've tried so far, to no avail:</p>
  
  <pre><code>Sum(IIF([QUALITY]&lt;=9.0,1.0,0.0))
  Sum(Convert(IIF(QUALITY&lt;=9.0,1.0,0.0), 'System.Double'))
  Sum(IIF(Convert(QUALITY, 'System.Double')&lt;=9.0,1.0,0.0))    
  </code></pre>