How can I create a derived measure field dynamically, that calculates the distinct count of another field?
For example, take the flat table below that contains raw data depicting a list of men who went to an events and met women:
Male_Name
Event_Name
Female_Name
Jack
Concert
Ashley
Brittney
Party
Steph
Linda
Mixer
Amber
Bob
Ginger
Gail
Sophia
Chad
The following Pivot Grid shows the Event_Name as columns, Male_Name as rows and Number_Of_Girls_Met as the measure which is derived from the distinct count of Female_Names:
2
1
3
0
How do I make the measure field Number_Of_Girls_Met of type integer, without setting this up in the database?
please ignore that last post, it's late and i didn't notice the double "count"
NOTE: with all my code and solutions, please refer to my original posting for the fictional flat data source.
As I was looking at the available AggregatorTypes, I realized that DistinctCount fits more of what I'm trying to accomplish. However, I get a compile time error saying : 'Infragistics.Olap.AggregatorType' does not contain a definition for 'DistinctCountCount' even though it shows up on intellisense.
Plamen, your suggestion sounds more like what we need. This is what I did so far. All the default fields show up, I did not get any errors BUT I don't see the measure "Female Count" showing up on the data selector. Am I missing anything? I'm using code behind because I'm having a hard time getting the XAML binding to work, that'll be a separate post later.
CubeMetadata cubeMetadata = new CubeMetadata(); cubeMetadata.DataTypeFullName = typeof(BoyMeetsGirl).FullName; cubeMetadata.DisplayName = "Boy Meets Girl"; cubeMetadata.DimensionSettings.Add( new DimensionMetadata(){ SourcePropertyName ="Female_Name", DimensionType = DimensionType.Measure, DisplayName = "Female Count", DisplayFormat ="{}{0}", AggregatorType = AggregatorType.Count });
FlatDataSource dataSource = new FlatDataSource();dataSource.ItemsSource = DatingViewModel.BoyMeetsGirlObservableCollection;dataSource.CubesSettings.Add(cubeMetadata);pivotDataSelectorSampleDetails.DataSource = dataSource;pivotGridSampleDetails.DataSource = dataSource;
Hello,
If you are using XmlaDataSource you need to create/set up this in BI studio.
If the case is with FlatDataSource if you want to deal with this with less effort you'll need at least numeric property exposed by your data object, so you can create a measure for that property. That's because of the way the default measures are created.
<olap:FlatDataSource.CubesSettings>
<olap:CubeMetadata
DataTypeFullName="YourDataClassFullName"
DisplayName="My Data">
<olap:DimensionMetadata SourcePropertyName="YourNumericPropertyName"
DimensionType="Measure"
DisplayName="DisplayNameForYourMeasure"
DisplayFormat="{}{0}"
AggregatorType="Count"/>
</olap:CubeMetadata>
</olap:FlatDataSource.CubesSettings>
This code will create a measure that will act in the way you have described and will calculate the common count of the members involved.
However, if it's not acceptable for you to create another property for your class then you'll need to create a custom aggregator as Yanko has proposed. It seems the online sampe is missing the code of the custom aggregator, so I have attached it. In your case the TopCountCache class just need to store the absolute number of AddCount method is called.
Regards.Plamen.
I don't think that's the same thing I'm asking for Nikolov. I specifically need a field that would show up in the "Measures" section of the tree that you will just have to drag into the measures section of the pivot grid. That Field should be, in sql terms, a DISTINCT COUNT of an existing field.