Problem with SUM on Matrix blocks I have some Matrix blocks where I need to sum one of the fields within, but I only want to sum it when another field within that block is or is not empty.
{% set reimbursementAmount = craft.matrixBlocks()
  .relatedTo(cat)
  .fieldId(9)
  .sum('field_item_reimbursementAmount')
  .specialCase(':empty:')
  %} 

With this, I get an error:
Impossible to invoke a method (&quot;specialCase&quot;) on a string variable (&quot;101.00&quot;).
How do I sum the desired field, but only where another field (specialCase) is empty (or is not empty, as the case may be).
I haven't tested this, but I think .sum() will execute your query, so put it at the end:
{% set reimbursementAmount = craft.matrixBlocks()
  .relatedTo(cat)
  .fieldId(9)
  .specialCase(':empty:')
  .sum('field_item_reimbursementAmount')
%}