Programmatically add 'Difference From' between groups

4 posts, 0 answers
  1. Robert
    Robert avatar
    3 posts
    Member since:
    Jul 2013

    Posted 26 Aug 2014 Link to this post

    Hello all,

    I'm using PivotGrid in a project. Users love it.

    I'd like to programmatically add calculations between groups. In my case i'm trying to calculate the difference between sums in Fiscal Years. I can do it manually from the UI, as seen in the screenshot, so I think it could be done in code, but I don't know how to do it. 

    Any suggestions?

    Thanks
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 29 Aug 2014 Link to this post

    Hello Robert,

    Thank you for writing.

    By using the drop-down menu of the items in the Values list, you can modify settings related to the aggregate descriptors. When you select the "Difference From" option, you are actually modifying the existing PropertyAggregateDescription.TotalFormat property to Totals.DifferenceFrom

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    3 posts
    Member since:
    Jul 2013

    Posted 03 Sep 2014 in reply to Dess Link to this post

    Thank you Desislava. That's got me pointed in the right direction.

    I still have one more question, though. How can I name the group that I want to calculate the difference from? In my example, I'm looking at sums from Fiscal Year 2014 and Fiscal Year 2015. I'd like to calculate the difference from Fiscal Year 2014. What's the best way to do that?

    Much appreciated!
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 08 Sep 2014 Link to this post

    Hello Robert,

    Thank you for writing back.

    Here is a sample code snippet, demonstrating how to add programmatically 'DifferenceFrom' TotalFormat:
    LocalDataSourceProvider provider;
     
    public Form1()
    {
        InitializeComponent();
        this.LoadData();
     
        this.provider = new LocalDataSourceProvider() { ItemsSource = orders };
     
        provider.ColumnGroupDescriptions.Add(new DateTimeGroupDescription() { PropertyName = "Date", Step = DateTimeStep.Year });
        provider.ColumnGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "Promotion", GroupComparer = new GroupNameComparer() });
     
        provider.RowGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "Product", GroupComparer = new GroupNameComparer(), SortOrder = Telerik.Pivot.Core.SortOrder.Descending });
        provider.RowGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "Advertisement", GroupComparer = new GroupNameComparer() });
     
        provider.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "Quantity", AggregateFunction = AggregateFunctions.Sum });
        provider.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "Net", AggregateFunction = AggregateFunctions.Sum });
     
        provider.AggregatesPosition = PivotAxis.Columns;
        provider.AggregatesLevel = 2;
     
        this.radPivotGrid1.PivotGridElement.DataProvider = provider;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
     
        Telerik.WinControls.UI.PivotFieldList.Value pivotFieldListValue = radPivotFieldList1.ValuesControl.Items.First.DataBoundItem as  Telerik.WinControls.UI.PivotFieldList.Value;
        Telerik.WinControls.UI.PivotFieldList.FieldListViewModel flc = pivotFieldListValue.ParentList.Parent;
        IEnumerable<object> uniqueItems = flc.DataProvider.Results.GetUniqueKeys(PivotAxis.Columns, 0);
        object groupName = null;
        foreach (object item in uniqueItems)
        {
            groupName = item;
            break;
        }
     
        DifferenceFrom df = new DifferenceFrom()
        {
            Axis = PivotAxis.Columns,
            Level = 0,
            GroupName = groupName
        };
     
        provider.AggregateDescriptions[1].TotalFormat = df;
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top