Calculated Field

Posted by: normansiboro.ibn on 6 March 2018, 1:33 pm EST

    • Post Options:
    • Link

    Posted 6 March 2018, 1:33 pm EST

    is there any way to use calculated field in pivot grid as excel does in pivot table?

  • Posted 6 March 2018, 8:58 pm EST

    Could you please take a look at the OlapIntro Sample. This sample has a section which showcases how you can apply totals /group total

    http://demos.wijmo.com/5/angular/OLAPIntro/OLAPIntro/

    Please let me know in case my understanding is not correct.

  • Posted 6 March 2018, 10:43 pm EST

    I’ve seen and tried the tutorial.

    calculated field that I means is we can add column in pivot-grid and the value is the operation between some columns

    for example:

    I have 4 columns (product, country, sales, downloads)

    and I want to add a new column to the pivot grid for example ‘achievement’ which values is ((sales/download)*100)

  • Posted 8 March 2018, 1:13 am EST

    Hi,

    Calculated fields are not support in PivotGrid. If you intend this for display only, you can use FlexGrid.

    If you have specific requirement to display calculated fields in pivot grid, you can workaround like in the attached sample by handling formatItem event. In the sample ‘Sales*2’ field is calculated on the basis of ‘sales’ field. Refer to formatItem() method in app.ts.However it is not recommended

    ~nilay

    OlapShowAs.zip

  • Posted 8 March 2018, 3:22 pm EST

    Thank you for your explanation

    but I cannot find file app.ts in your sample ‘OlapShowAs.zip’

    could you send it once again?

  • Posted 8 March 2018, 4:55 pm EST

    Hi,

    Sorry, please find the correct sample attached.

    ~nilay

    OlapShowAs.zip

  • Posted 11 March 2018, 8:21 pm EST

    Hi,

    Could you explain how the licence work or how my web app is connected to my licence?

    thank you

  • Posted 12 March 2018, 9:10 pm EST

    The license detail are stored in the JS Dependencies for Wijmo 5. When you reference them license banner is not shown. If you want to download the licensed build then you can do so from your accounts section.

  • Posted 18 March 2018, 7:52 pm EST

    Thank you for your information.

    How about calculated field? is there any further update or addition to wijmo about calculated field, Because we are about to buy the license but calculated field is one of things that we are really concerned about.

    I hope calculated field can be added as a part of wijmo.

  • Posted 19 March 2018, 10:46 pm EST

    Hi,

    The enhancement request has been created for this with the internal tracking id 314546.

    This might be implemented in future releases if found feasible.

    ~Manish

  • Posted 10 September 2018, 6:21 am EST

    This has been added to the latest version of Wijmo (524+).

    In this latest version, the PivotField class has a getValue property of type function that can be used to calculate arbitrary field values. For example:

    // create a PivotEngine with calculated fields
    var ng = new wijmo.olap.PivotEngine({
      autoGenerateFields: false,
      itemsSource: getData(10000),
      showColumnTotals: 'GrandTotals',
      showRowTotals: 'Subtotals',
      fields: [
        { binding: 'product', header: 'Product' },
        { binding: 'date', header: 'Date', format: 'yyyy \"Q\"q' },
        {
           header: 'Range',
           dataType: 'String',
           aggregate: 'Cnt',
           getValue: function (item) {
             var sales = item.sales;
             return sales <= 13 ? 'Low' : sales >= 17 ? 'High' : 'Medium';
           }
        },
        { binding: 'sales', header: 'Sales', format: 'n0' },
        { binding: 'downloads', header: 'Downloads', format: 'n0' },
        {
          header: 'Conversion',
          dataType: 'Number',
          aggregate: 'Avg',
          format: 'p0', 
          getValue: function (item) {
            return item.downloads ? item.sales / item.downloads : 0;
          }
        }
      ],
      rowFields: ['Date', 'Range'],
      valueFields: ['Sales', 'Conversion']
    });
    
    

    Note that you can achieve similar results using the current version of wijmo.olap by adding the calculated fields to the raw data. For example:

    rawData.forEach((item) => {
      item.range = item.sales <= 13 ? 'Low' : item.sales >= 17 ? 'High' : 'Medium';
      item.conversion = item.downloads ? item.sales / item.downloads : 0;
    });
    
    

    The main advantage of the PivotField.getData approach is that it does not modify the source data.

    Thank you all for the suggestion and for the discussion!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels