public static void addTurnover(D010Invoices.Invoice invoice) { var turnoverTransactions = D010.loadTurnover(invoice.document); decimal total = 0; decimal? totalPaid = 0; if (turnoverTransactions.Rows.Count > 0) { total = (decimal)turnoverTransactions.Compute("sum(amount)", "true"); totalPaid = (decimal?)turnoverTransactions.Compute("sum(amount)", "document like 'AP*'"); if (totalPaid==null) { totalPaid = 0; } }.... so why do I get a casting error in the totalPaid line when the document does not start with "AP"?