Skip to content

Discussion on #OLAP/PivotPanel/Fields/Customize/FieldSettingsDialog/Calculated #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
theflasherman opened this issue Feb 7, 2021 · 6 comments

Comments

@theflasherman
Copy link

The Calculated Fields is wrong for this. The Conversion rate should be for the summary displayed, not an average of the underlying individual items.


OLAP/PivotPanel/Fields/Customize/FieldSettingsDialog/Calculated

@banzor
Copy link
Collaborator

banzor commented Feb 8, 2021

Hey, thanks for reporting this! You are absolutely correct.

The value we are showing is the average conversion per item (avg(sum(sales/downloads))), not the total conversion for each period (sum(sales)/sum(downloads)).

In Excel there is a way to calculate fields based on individual items (which is what we are doing here) or on group aggregates (which we do not support).

We are updating the sample to be a correct calculated field example.

@theflasherman
Copy link
Author

theflasherman commented Feb 9, 2021 via email

@banzor
Copy link
Collaborator

banzor commented Feb 12, 2021

Hey Brian, we have corrected this sample and it will be live in mid-March.

More importantly, we have added a getAggregateValue as an alternative to getValue. I think this will be exactly what you need.
Here is an example of usage:

    let ng = new 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',
                // use getValue to calculate the sales range (High, Medium, or Low)
                getValue: (item) => {
                    let 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',
                format: 'p0',
                // getAggregateValue computes an aggregate from a summary row (Sales/Downloads)
                getAggregateValue: row => row.Downloads ? row.Sales / row.Downloads : 0
            }
        ],
        rowFields: ['Date', 'Range'],
        valueFields: ['Sales', 'Downloads', 'Conversion']
    });

This is in our nightly build already if you want to give it a try now!

@theflasherman
Copy link
Author

theflasherman commented Feb 15, 2021 via email

@theflasherman
Copy link
Author

Hi Chris

Further to the above, if I remove 'Sales' and 'Downloads' from the valueFields then the 'Conversion' doesn't calculate. My use case here is for a pivot chart on the pivotEngine where I only want to show the 'Conversion' values as the 'Sales' and 'Downloads' numbers are on a different scale. I think this may make it more complex to implement so sorry for being a pain.

Kind regards
Brian

@banzor
Copy link
Collaborator

banzor commented Feb 22, 2021

Hey Brian, thanks for trying (and suggesting) the new feature!

As for the two points you made...

  1. That is true. getValue works on the raw data items, so it uses the binding names. getAggregateValues works on aggregated row items, so it uses field captions instead of bindings.
  2. That is a design limitation (for good performance). getAggregateValues works on aggregated row items, so it can only use fields that are present in the output view. If you don’t want to show some of those fields on the grid, you could set their width property to zero.

Thanks again for reporting the issue and making the great suggestion! We plan to release it next month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants