0

When the cube is created and sum is chosen it returns a sum and a count in the value context when output as json. How can that be turned off so only the sum value is returned?

//define cube pivot
            var cubeData = new PivotData(
                new[] { "CloseDate", "StageName", "Type", "OpportunityName","Industry", "IsClosed", "IsWon" },
                new SumAggregatorFactory("Amount"),
                true);

json = new
            {
                cubeData,
            };

            return json;

Output shows

  "cubeData": [
    {
      "key": [
        "2019-07-05T00:00:00",
        "Stage Value",
        "Type Value",
        "Opportunity Name Value",
        "Industry Value",
        false,
        false
      ],
      "value": {
        "value": 35000.0,
        "count": 1
      }
    },
Jason
  • 13
  • 3

1 Answers1

0

PivotData has 2 serializable properties:

Count and Value.

If you want to prevent Value from being serialized, you would need to modify the PivotData class to [JsonIgnore] the Count property.

Alternatively, depending on your json implementation you can just remove the "count" element before returning.

            json = new
            {
                cubeData,
            };
            json["value"].Value<JObject>().Remove("count");

            return json;
Erik Overflow
  • 2,220
  • 1
  • 5
  • 16