【问题标题】:OLAP filtering hierarchy confusionOLAP 过滤层次混淆
【发布时间】:2019-07-23 21:57:27
【问题描述】:

我正在尝试使用我的文件中的指定值来确定要应用于我的 OLAP 数据透视表的过滤器,但由于存在的层次结构,我正在努力正确地标注自定义数组。

录制时我得到以下结果

ActiveSheet.PivotTables("PivotTable3").PivotFields( _
        "[Date].[Date Hierarchy].[Month]"). _
        VisibleItemsList = Array( _
        "[Date].[Date Hierarchy].[Year].&[2019].&[2]" _
        )

问题部分是同时选择年份和月份的部分。

"[Date].[Date Hierarchy].[Year].&[2019].&[2]" _
        )

我已经成功编写了一个类似的脚本,我只需要选择它们没有通过层次结构连接但年/月组合让我陷入循环并且无法分开的年份和月份。

Dim pt As PivotTable
Dim Field As PivotField
Dim Field2 As PivotField
Dim year As String
Dim month As String


Set pt = Worksheets("Csum").PivotTables("PivotTable1")
Set Field = pt.PivotFields("[CC Date].[CC Year].[CC Year]")
Set Field2 = pt.PivotFields("[CS Date].[CS Month].[CS Month]")
year = Worksheets("Sheet1").Range("B8")
month = Worksheets("sheet1").Range("B9")


Sheets("CashSummary").Select


With pt
    Field.CurrentPageName = "[CC Date].[CC Year].&[" & year & "]"
    Field2.CurrentPageName = "[CS Date].[CS Month].&[" & month & "]"
End With

【问题讨论】:

    标签: excel vba pivot filtering olap


    【解决方案1】:
    Function SetFilterOfMonth(yr, mon)
    mFilter = "&[" & yr & "].&[" & mon & "]"
    
    ActiveSheet.PivotTables("PivotTable3").PivotFields( _
            "[CS Date].[CS Date Hierarchy].[CS Year]" _
            ).VisibleItemsList = Array("")
        ActiveSheet.PivotTables("PivotTable3").PivotFields( _
                "[CS Date].[CS Date Hierarchy].[CS Month]" _
                ).VisibleItemsList = Array( _
                "[CS Date].[CS Date Hierarchy].[CS Year]." & mFilter _
                )
    
    End Function
    
    Sub Test()
        mYear = Worksheets("Sheet1").Range("B8")
        mMonth = Worksheets("Sheet1").Range("B9")
        SetFilterOfMonth mYear, mMonth
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多