How to automatically filter a Pivot Table when generating a report?

Created by Compettia Support Team, Modified on Fri, 26 Sep at 6:29 PM by Compettia Support Team

In a DataCycle Reporting (DCR) report that contains a Pivot Table, it is possible to automatically filter the Pivot Table using the DCR "Run Macro" task. To do this, you can use the following macro, which must be included in the report template design:

DCR "Run Macro" task configuration:

  • Macro: FilterPivotTable

  • Parameters: Field to filter, Value to filter

Macro to include in the report design (within the Excel template's VBA code):


---
Sub filtraTD(fieldname As String, Value As String)
Dim pt As PivotTable
Dim apfield As PivotField

If Value = "" Then Exit Sub
Set pt = Sheets("Visión Dinámica").PivotTables("Cubo")
Set apfield = pt.PivotFields(fieldname)
apfield.CurrentPage = Value
If apfield.CurrentPage <> Value Then
MsgBox "Error:" & Err.Description
End If
End Sub

---


This macro is valid if the template contains a worksheet named "Visión Dinámica" and a Pivot Table named "Cubo".


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article