1 field, multiple types

Hi there,

Is it possible to apply different aggregation types to a single field for pivot view?

I want to show both Sum and PercentOfColumnTotal values for a single field.

I looked at calculated fields, but I don't know how to get the column total using it.

Please advise.


Regards,

Jose


5 Replies 1 reply marked as answer

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team May 16, 2022 01:13 PM UTC

Hi Jose,


Please use CalculatedFieldSettings to create same field with different aggregation types in code-behind. Please refer the below code example.


Code Example:

this.dataSourceSettings = {

      calculatedFieldSettings: [

        {

          name: 'Min',

          formula: '"Min(Amount)"',

        },

        {

          name: 'Product',

          formula: '"Product(Amount)"',

        },

        {

          name: 'Avg',

          formula: '"Avg(Amount)"',

        },

      ],

    }


However, you can do this through calculated Field UI by enabling allowCalculatedField property.


Meanwhile, we have prepared a sample for your reference.

Sample: https://stackblitz.com/edit/angular-mdk1wz-bjc94q?file=app.component.html,app.component.ts


Please see the below UG document for more information on the "CalculatedField" option.

Document: https://ej2.syncfusion.com/angular/documentation/pivotview/calculated-field/


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.



JO Jose May 16, 2022 11:54 PM UTC

How can I do a PercentOfColumnTotal ​using CalculatedField?



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team May 17, 2022 12:28 PM UTC

Hi Jose,


We would like to inform you can create a calculated field using only the aggregate types listed below. You can set aggregation types other than those listed below by using the type property in code-behind to set it to a specific field. For example, you can set the  PercentOfColumnTotal  as default aggregate type to “Amount” field use the calculated field option to set the Sum type. Please refer the below code example.


Supported aggregation types for calculated field:

  • Sum

  • Count

  • Distinct Count

  • Product

  • Min

  • Max

  • Avg

  • Median

  • PopulationVar

  • SampleVar

  • PopulationStDev

  • SampleStDev


Code Example:


this.dataSourceSettings = {

      values: [

        { name: 'Sold'caption: 'Units Sold' },

        {

          name: 'Amount',

          caption: '% of column Total',

          type: 'PercentageOfColumnTotal',

        },

        name: 'Sum'caption: 'Sum of Amount'type: 'CalculatedField' },

        {

          name: 'Product',

          caption: 'Product of Amount',

          type: 'CalculatedField',

        },

        { name: 'Avg'caption: 'Avg of Amount'type: 'CalculatedField' },

      ],

      calculatedFieldSettings: [

        {

          name: 'Sum',

          formula: '"Sum(Amount)"',

        },

        {

          name: 'Product',

          formula: '"Product(Amount)"',

        },

        {

          name: 'Avg',

          formula: '"Avg(Amount)"',

        },

      ],

    }


Meanwhile, we have modified your sample for your reference.


Sample: https://stackblitz.com/edit/angular-mdk1wz-lr9c72?file=app.component.html,app.component.ts


Please refer the below UG document for more information on the "CalculatedField" and “Aggregation”.


Document: https://ej2.syncfusion.com/angular/documentation/pivotview/calculated-field/

https://ej2.syncfusion.com/angular/documentation/pivotview/aggregation/


Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.


Marked as answer

JO Jose May 17, 2022 01:02 PM UTC

I feel so dumb for not being able to think of this approach. Thanks a lot for your help.

Regards,

Jose



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team May 18, 2022 07:49 AM UTC

Hi Jose,


Please let us know if you have any other queries. We are always happy to assist you.


Regards,

Angelin Faith Sheeba.


Loader.
Up arrow icon