Hi,
In your samples Filtering, you are using IFilterViewModel to filter the data according to what the user chooses as months.
I tried it and it worked fine with my grid that has the following format which is Brands vs Dates data.
this.Rows = XmlaDataSource.GenerateInitialItems("[Brands].[Brands]");
this.Columns = XmlaDataSource.GenerateInitialItems("[Date].[Date]");
this.Measures = XmlaDataSource.GenerateInitialItems("msvalue");
However, i have another grid that has the following info:
this.Measures = XmlaDataSource.GenerateInitialItems("msvalue, msvolume");
with no columns and i would like to filter both measures according to what the user chooses in a drop down. but i can't use the IFilterViewModel because it is a IMeasureViewModel. and i didnt know how to go on from there. can you please help?
Below is the code used for filtering using the IFilterViewModel.
private void FilterDates(DateTime beginning, DateTime ending)
{
//Run filtering in background process in order to not hang the main UI of your app
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += WorkerDoWork;
worker.RunWorkerCompleted += (s, e) =>
bool allUnchecked = true;
IFilterViewModel fvm = FindDateViewModel((DataSourceBase)this.pivotGrid.DataSource);
foreach(IFilterMember filterMember in fvm.FilterMembers)
if (filterMember.IsSelected != false)
allUnchecked = false;
break;
}
if (allUnchecked)
MessageBox.Show("There is no data for the last " + (this.monthsToFilter.SelectedItem as ComboBoxItem).Content.ToString() + " months");
else
this.pivotGrid.DataSource.RefreshGrid();
this.isBusyIndicator.Visibility = Visibility.Collapsed;
};
this.isBusyIndicator.Visibility = Visibility.Visible;
worker.RunWorkerAsync(new WorkerArguments()
DataSource = this.pivotGrid.DataSource as DataSourceBase,
Beginning = beginning,
Ending = ending
});
void WorkerDoWork(object sender, DoWorkEventArgs e)
WorkerArguments args = e.Argument as WorkerArguments;
if (args == null)
return;
//Find the Date view model or if not found create it in the Filters area
IFilterViewModel fvm = FindDateViewModel(args.DataSource) ?? CreateViewModel(args.DataSource);
if (fvm == null) return;
//Manual reset event will be used to wait for the members to load
//when they are expanded or selected
fvm.LoadFilterMembersCompleted += (sender1, e1) => _manualResetEvent.Set();
if (fvm.FilterMembers != null)
foreach (IFilterMember member in fvm.FilterMembers)
//Recursively go through all members that need to be interacted with
DrillIn(member, args);
e.Result = fvm;
private IFilterViewModel FindDateViewModel(DataSourceBase dataSource)
for (int i = 0; i < dataSource.Filters.Count; i++)
if (((IFilterViewModel)dataSource.Filters[i]).Caption == "Date")
return dataSource.Filters[i] as IFilterViewModel;
for (int i = 0; i < dataSource.Rows.Count; i++)
if (((IFilterViewModel)dataSource.Rows[i]).Caption == "Date")
return dataSource.Rows[i] as IFilterViewModel;
for (int i = 0; i < dataSource.Columns.Count; i++)
if (((IFilterViewModel)dataSource.Columns[i]).Caption == "Date")
return dataSource.Columns[i] as IFilterViewModel;
return null;
private IFilterViewModel CreateViewModel(DataSourceBase dataSource)
foreach (IDimension dim in dataSource.Cube.Dimensions)
foreach (IHierarchy hierarchy in dim.Hierarchies)
if (hierarchy.UniqueName == "[Date].[Date]")
IFilterViewModel fvm = dataSource.CreateFilterViewModel(hierarchy);
this.pivotGrid.Dispatcher.BeginInvoke(
() => this.pivotGrid.DataSource.Filters.Add(fvm)
);
return fvm;
private void DrillIn(IFilterMember filterMember, WorkerArguments args)
_manualResetEvent = new ManualResetEvent(false);
//Expand all levels to the individual date level
//and then compare if each date is between the start and end date.
//If it is select it, otherwise disselect it.
if (filterMember.Member.LevelName == "Dates")
if (
(DateTime.Parse(filterMember.Member.Caption).CompareTo(args.Beginning) >= 0) &&
(DateTime.Parse(filterMember.Member.Caption).CompareTo(args.Ending) < 0)
)
this.Dispatcher.BeginInvoke(() => filterMember.FilterSource.IsSelected = true);
this.Dispatcher.BeginInvoke(() => filterMember.FilterSource.IsSelected = false);
if (!filterMember.IsExpanded)
this.Dispatcher.BeginInvoke(() => filterMember.IsExpanded = true);
_manualResetEvent.WaitOne();
for (int i = 0; i < filterMember.FilterMembers.Count; i++)
DrillIn(filterMember.FilterMembers[i], args);
Hello Nazha,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
I checked what you said and did the following in my CustomAggregator. It worked. I checked when the flat data source's columns are expanded and so calculated them as sum. and when the rows are expanded i calculate as average.
public override IAggregationResult<double, double> Evaluate(IAggregationResult<double, double> oldResult, IAggregateable aggregateable, IEnumerable items)
double result = 0;
double currentValue = 0;
double notemptyValue = 0;
double naCount = 0;
bool notallNA = false;
bool lrowexpanded = false;
bool lcolexpanded = false;
IFilterViewModel rowfvm = this._flatDataSource.Rows[0] as IFilterViewModel;
if (rowfvm.FilterMembers != null)
foreach (IFilterMember member in rowfvm.FilterMembers)
if (member.IsExpanded == true)
lrowexpanded = true;
IFilterViewModel colfvm = this._flatDataSource.Columns[0] as IFilterViewModel;
if (colfvm.FilterMembers != null)
foreach (IFilterMember member in colfvm.FilterMembers)
lcolexpanded = true;
if (lcolexpanded == true || lrowexpanded == true)
foreach (var item in items)
currentValue = (double)aggregateable.GetValue(item);
if (currentValue != -1)
naCount += currentValue;
result += currentValue;
notemptyValue += 1;
notallNA = true;
result = -1;
if (lrowexpanded == true)
naCount = naCount / notemptyValue ;
if (result == -1 && notallNA == false)
return new SingleResult<double>(result);
return new SingleResult<double>(naCount);
This sample uses XmlaDataSource and value calculations in this case depend on the definitions of the analysis service.
But in this Sample:
http://samples.infragistics.com/sldv/RunSamples.aspx?cn=pivot-grid#/pivot-grid/calculated-members
for the same Measure "Internet Sales Amount", you have summed up the values for All Period and computed the values as Average for All Geographies.
How could this be?
The aggregator is per measure and it has nothing with the hierarchies that you have added to the rows/columns. Currently we don’t support such conditional aggregating.
Regards.Plamen.