Is it possible to add a measure dynamically bypassing th data source altogether.
For example, If an Excel file is loaded in the cube and displayed in the grid. Is it possilble to have the user create a new measure and added into the collection of measure. This measure will be essentialy a sum and a product of two other measure. Also, we want to display it right next to other measure in the grid.
Thanks.
If I did not want to display the "cost" measure .. how is this suppsed to work. In the example you are forcing user to view the "Cost" measure..Will this snippet work without these lines..?
DimensionMetadata costMetadata = new DimensionMetadata
{
SourcePropertyName = "Cost",
DisplayName = "Cost",
DimensionType = DimensionType.Measure,
DisplayFormat = "{0:C3} "
}
If I understand you correct you want a measure which operates and uses as a source the measures which the user adds to Measures collection of the FlatDataSource.
Have a look at the snapshot – the Compound measure is calculated using both Cost and Units (assuming we have these two columns in the excel file) measures as for each instance it calculates the product of their values.
I have attached the file with the source code. There is no matter which is the source property used for your calculated measure but you still need to specify it when you create the dimension metadata for it. I think it be easy for you to modify it and implement the logic you want.
The new aggregator accepts an instance of the FlatDataSource in its constructor so constructing the dimension metadata is changed. You need these lines of code:
flatDataSource.DimensionsGenerationMode = DimensionsGenerationMode.Mixed;
DimensionMetadata calcMeasureMetadata = new DimensionMetadata
DisplayFormat = "{0:C3}",
DisplayName = "Compound measure",
Aggregator = new CustomMeasureAggregator(flatDataSource)
};
cubeMetadata.DimensionSettings.Add(costMetadata);
cubeMetadata.DimensionSettings.Add(calcMeasureMetadata)
PPilev.
Please ignore my last post, it was a little in accurate.
I want to be able to add the Measure once the grid is bound the and user chooses to add a measure (dynamically generated and based on other measures) to the grid.
Right now, as soon as I add this new measure..it still removes the one it is based on.
It does not work for me.
I want to be able to add the dimension once the grid is bound the and user chooses to add a measure (dynamically generated and based on other measures) to the grid/UI.
As soon as I add this new measure..it still removes the one it is based on.
You need to set
In this way you can add additional dimensions besides the dimensions built over the properties exposed by your data class.
Because the measure with your custom aggregator will override the default one you need to recreate the default:
DisplayFormat = "{0:C3}"