Hi,
I've got a XamPivotGrid with a FlatDataSource working and I haven't been able to get the custom/ calculated measures working.
I need to achieve a weighted sum where the values and the weights are two measures present on the pivot table.
I was following the response from https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/45131/calculated-custom-measures-for-flatdatasource-in-xampivotgrid?ReplySortBy=CreatedDate
but the example link provided died and the pasted code has issues.
thanks
Hello Claudio,
The FlatDataSource does not currently support calculated measures. Calculated measures are only supported on XMLA data sources.
If you need a calculated measure then I recommend adding another field to your underlying data source that represents the calculated measure. For example:
public class Sale{ public double AmountOfSale { get; set; } public double DoubledAmountOfSale { get { return AmountOfSale * 2.0; } }}
We have a online topic that walks through on creating calculated measures. You may also refer to the following sample for more details. See below.
PercentageAggregator.zip
You can suggest new product ideas for future versions (or vote for existing ones) at <https://www.infragistics.com/community/ideas>. Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you. Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. You can also link back to this thread for additional details.
Let me know if you have any questions.
Turns out, it can be done.
By setting a custom aggregator and manually adding it to the dimension settings of the cube in the flat data source, you can add a custom measure that may be calculated in any form needed. (a weighted average in my case).
Sources:
setting up custom aggregators:
https://www.infragistics.com/help/wpf/xampivotgrid-us-customaggregators
Aggregator example with weighted sum help class. (although it has some issues that were fixed in a comment below)
https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/45131/calculated-custom-measures-for-flatdatasource-in-xampivotgrid/331675#331675
The only thing that was missing from those two references is how the aggregator should be actually applied to the FlatDataSource, because in the first example, the agregator is applied to CubeSettings[0] but that list was empty thus throwing a null reff exception.
For me it looked something like this.
CubeMetadata cube = new CubeMetadata(); //weirdType is a dynamically generated type, use typeof(**yourtype**).FullName for other cases. cube.DataTypeFullName = weirdType.FullName; cube.DisplayName = "weird type"; DimensionMetadata testMetadata = new DimensionMetadata { SourcePropertyName = "prop1", DisplayName = "test", DimensionType = DimensionType.Measure, Aggregator = new TypeBuilderNamespace.IgWeightedAverageAggregator("prop1", "weightProp") }; cube.DimensionSettings.Add(testMetadata); FlatDataSource dataSource = new FlatDataSource(); dataSource.CubesSettings.Add(cube); //data is a collection of weirdType objects dataSource.ItemsSource = data; //then set that dataSource.
so the weird type has a property "prop1" that has values that should be weighted by "weightProp". the "test" displayed doesn't exists as a property of weirdType