How to filter pivot table programmatically

S

Soni

Hi there,

I have setup a pivot table in vb.net, but want to be able to default
the filter axis. For example I have added a Time dimension to the
Filter Axis, something like this ...


..FilterAxis.InsertFieldSet(activepivotview.FieldSets("Time"))


At the moment the fieldset defaults to the "All value", I want to
default it to a different value.

Does anyone know how to do this?

Thanks for your help

Nehal Soni
MIS Anaylst
 
S

Soni

Hi there,

I have setup a pivot table in vb.net, but want to be able to default
the filter axis. For example I have added a Time dimension to the
Filter Axis, something like this ...

.FilterAxis.InsertFieldSet(activepivotview.FieldSets("Time"))

At the moment the fieldset defaults to the "All value", I want to
default it to a different value.

Does anyone know how to do this?

Thanks for your help

Nehal Soni
MIS Anaylst

I have found the solution to this, you need to refer to the method
IncludedMembers, in this example I get the most recently added member
of the time dimension, get its unique name and then use it to set the
filter dimension:

'Get last date member index
Dim lDateIndex As Integer
lDateIndex =
Me.AxPivotTable1.ActiveData.FilterAxis.FieldSets(0).Member.ChildMembers.Count
- 1

'Get last date member

Dim pm As Microsoft.Office.Interop.Owc11.PivotMember
pm =
Me.AxPivotTable1.ActiveData.FilterAxis.FieldSets(0).Member.ChildMembers.Item(lDateIndex)

'set filter dimension


Me.AxPivotTable1.ActiveData.FilterAxis.FieldSets(0).Fields(0).IncludedMembers
= pm.UniqueName 'e.g. '[Time].[Time].[&21042008], or an array of
values (see
http://groups.google.co.uk/group/mi...&lnk=st&q=change+filter++OWC#eb4fcd31c66da044)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top