Esempio n. 1
0
 public void EvaluateCalculatedFieldFormulaNullValue()
 {
     using (var helper = new TotalsFunctionHelper())
     {
         var fieldValues = new Dictionary <string, List <object> >
         {
             { "Count", new List <object> {
                   1, 2, 3, 4
               } },
             { "Cost", new List <object> {
                   5, 6, 7, 8
               } }
         };
         helper.AddNames(new HashSet <string>(fieldValues.Keys));
         var result = helper.EvaluateCalculatedFieldFormula(fieldValues, null);
         Assert.AreEqual(null, result);
     }
 }
Esempio n. 2
0
        private double?GetCalculatedFieldTotal(PivotItemTreeNode node, ExcelPivotTable pivotTable, CacheFieldNode cacheField)
        {
            var totalsFunction   = new TotalsFunctionHelper();
            var calculatedFields = pivotTable.CacheDefinition.CacheFields.Where(f => !string.IsNullOrEmpty(f.Formula));

            PivotTableDataManager.ConfigureCalculatedFields(calculatedFields, totalsFunction, pivotTable);
            var fieldNameToValues = new Dictionary <string, List <object> >();

            foreach (var cacheFieldName in cacheField.ReferencedCacheFieldsToIndex.Keys)
            {
                var values = pivotTable.CacheDefinition.CacheRecords.GetChildDataFieldValues(node.CacheRecordIndices, cacheField.ReferencedCacheFieldsToIndex[cacheFieldName]);
                fieldNameToValues.Add(cacheFieldName, values);
            }
            var total = totalsFunction.EvaluateCalculatedFieldFormula(fieldNameToValues, cacheField.ResolvedFormula);

            if (double.TryParse(total.ToString(), out var result))
            {
                return(result);
            }
            return(null);
        }