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.
Hello,
What I have understood based on your snapshots and your code is as follows:
You have a column named Test and your calculated measure, named “A New Measure”, is based on this column but when the result is visualized you have lost the Test column. I don’t know the content of _measures variable you have used to populate the measures, so I’m not sure if you have tried to load it. I guess that there is no such measure Test created because you have not added metadata for it.
This is because if you want both the “Test” and “A New Measure” to exist you need to explicitly add a metadata for Test measure because the metadata of “A New Measure” has overridden the default one. If you put a XamPivotDataSelector control on your page you’ll be able to see the measures that are created for your current metadata configuration.
Adding this metadata item to the dimensions metadata collection should make the trick:
DimensionMetadata testMeasureMetadata = new DimensionMetadata
{
SourcePropertyName = "Test",
DimensionType = DimensionType.Measure,
DisplayFormat = this._dynamicMeasureFormat,
DisplayName = "Test (Default)"
};
PPilev.
Column 'test' is hidden automatically and replaced with 'A New Measure' column which is sum of col1 and col2. Here is the code ...
private
FlatDataSource CreateDataSource(Stream fileStream)
{_flatDataSource = new FlatDataSource();
ExcelDataConnectionSettings excelDataSettings =new ExcelDataConnectionSettings { FileStream = fileStream, GeneratedTypeName = "ExcelData", WorksheetName = "MMExample" };
_flatDataSource.ConnectionSettings = excelDataSettings;
_flatDataSource.DimensionsGenerationMode =
DimensionsGenerationMode.Mixed;
_flatDataSource.Cube =
);
_flatDataSource.Rows =
DataSourceBase.GenerateInitialItems("[Asset Class].[Asset Class],[Trading Desk].[Trading Desk]"
_flatDataSource.Measures =
DataSourceBase
.GenerateInitialItems(_measures);
CubeMetadata cubeMetadata = new CubeMetadata()
DataTypeFullName =
"ExcelData"
,
DisplayName =
"ESPExample Data"
if
(_dynamicMeasureRequested)
CustomMeasureAggregator agg = new CustomMeasureAggregator
(_flatDataSource);
agg.ColumnNames = _columnNames;
agg.Operations = _operations;
DimensionMetadata calcMeasureMetadata = new
DimensionMetadata
SourcePropertyName =
"Test"
DimensionType =
DimensionType
.Measure,
DisplayFormat = _dynamicMeasureFormat,
DisplayName = _newDynamicMeasureName,
Aggregator = agg
cubeMetadata.DimensionSettings.Add(calcMeasureMetadata);
_flatDataSource.CubesSettings.Add(cubeMetadata);
}
#region
Code will only work in version 11.1 - hierachry between year/months.
#endregion
) };
stringDataDescriptor.AddLevel<
string>(s => "All", "All Values"
string>(s => s, "Members"
_flatDataSource.HierarchyDescriptors.Add(stringDataDescriptor);
return
_flatDataSource;
this is the screenshot before. I am using a test measure to replace it with the actual measure later. I will also port the 'after' snapshot
It will be very helpful if you send a snapshot of how the selector looks like and list the metadata items you have added to cube metadata.
Also, That hiding problem is still there.