User-Defined Calculated Fields

4 posts, 0 answers
  1. Brett
    Brett avatar
    10 posts
    Member since:
    Dec 2013

    Posted 17 Dec 2015 Link to this post

    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

  2. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 18 Dec 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Brett
    Brett avatar
    10 posts
    Member since:
    Dec 2013

    Posted 19 Jan in reply to Nasko Link to this post

    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

  5. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 21 Jan Link to this post

    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
Back to Top