This is a migrated thread and some comments may be shown as answers.

User-Defined Calculated Fields

3 Answers 63 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 1
Brett asked on 17 Dec 2015, 04:58 PM

Hi -

I have been following the documentation on Calculated Fields (http://docs.telerik.com/devtools/wpf/controls/radpivotgrid/features/localdatasourceprovider/local-calc-fields) to configure some custom calculated fields that are sums of a set of other fields. For example, I have Fields A, B, and C in my data provider, and I created a calculated field to sum the totals of each of them into one field that they can include in the PivotGrid if they want.

However, I would really like to give my users the ability to setup sums of any number of fields of their choosing. For example, they may want to see a field represented by a sum of Fields A and B, but not C.

Is there a way to offer them the ability to create their own calculated fields? If not, do you any recommendation for how I might achieve something like this?

Thanks,
Brett

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 18 Dec 2015, 01:50 PM
Hello Brett,

The desired by you functionality of RadPivotGrid is curretnly not provided out of the box. However, you could try to implement and build it by your own - we could assist you in case you face an issues during your implementation. 

So, basically you would need to have an initially prepared CalculatedField class that should contain all of the desired RequiredFuields (for your scenario A, B and C). Next, using your UI (you could use a ListBox for example)  you need to select the desired fields. Using these selected fields you need to implement your custom logic inside the CalculatedFields class and extract and return the needed expression as DoubleAggregateValue:
return new DoubleAggregateValue(a * b);

We hope this will help you as a start point for achieving the desired functionality. If you have any further questions or concerns, please let us know.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Brett
Top achievements
Rank 1
answered on 19 Jan 2016, 07:48 PM

Hi Nasko -

Thank you for the guidance here, and apologies for the late response.

Using your suggested approach as a guide, I actually went one step further. I was able to implement a completely dynamic calculated field representing the sum of all of the aggregates currently selected by the user. I was able to achieve this by passing an instance of my LocalDataSourceProvider into my CalculatedField implementation. From this, I can see which aggregates are already selected and sum them into my calculated total. So this new calculated total is dynamic, depending on all the other sums.

Thanks for the help!

Best,
Brett

0
Nasko
Telerik team
answered on 21 Jan 2016, 11:58 AM
Hi Brett,

I am really glad to hear that you were able to achieve the desired functionality and even to be able to extend it. Thank you also for sharing the approach you used with the community.

If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PivotGrid
Asked by
Brett
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Brett
Top achievements
Rank 1
Share this question
or