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

Programmatically add 'Difference From' between groups

3 Answers 79 Views
PivotGrid and PivotFieldList
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 26 Aug 2014, 07:58 PM
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

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Aug 2014, 12:52 PM
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.
 
0
Robert
Top achievements
Rank 1
answered on 03 Sep 2014, 04:11 PM
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!
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Sep 2014, 01:16 PM
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.
 
Tags
PivotGrid and PivotFieldList
Asked by
Robert
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Robert
Top achievements
Rank 1
Share this question
or