简体   繁体   English

Excel 数据透视表报表筛选器

[英]Excel Pivot Table Report Filter

Fed by powerquery queries I have a main Pivot table (2.5+m lines, so not loaded to the sheet nor the data model as I want to use report filters).通过 powerquery 查询馈送我有一个主数据透视表(2.5+m 行,因此未加载到工作表或数据模型中,因为我想使用报告过滤器)。 Using the "show report filter pages" I split this pivot in multiple subsheets that I export and redistribute.使用“显示报告过滤器页面”,我将此数据透视表拆分为多个子表,然后导出和重新分发。 The problem is that even the subsheets get the full datasource :(, so I'm stuck with:问题是,即使是子表也能获得完整的数据源 :(,所以我坚持:

  1. Edit the query, add filter, refresh the pivot an all this for each entity (cumbersome option).编辑查询,添加过滤器,刷新每个实体的所有这些数据透视表(繁琐的选项)。
  2. Give a pivot with the full source to all entities (not an option).为所有实体提供一个包含完整源的数据透视表(不是一个选项)。
  3. Uncheck the "save source data with file" (now the pivot is not editable anymore for the entities).取消选中“使用文件保存源数据”(现在实体不再可编辑数据透视)。

Basically I just need to be able to interact with the pivot source trough vba but based on my research this is not possible without refreshing all queries (option 1).基本上,我只需要能够通过 vba 与枢轴源进行交互,但根据我的研究,如果不刷新所有查询(选项 1),这是不可能的。 Alternatively, I could fall back on loading to the dataModel, copy the pivot with vba but then it seems I cannot "remove lines" trough vba in the dataModel.或者,我可以回退到加载到数据模型,用 vba 复制枢轴,但似乎我无法通过数据模型中的 vba“删除线”。

Any other ideas?还有其他想法吗? I cannot believe I'm the only one that finds it stupid that the report filter is not also filtering the pivot source, seems logic to me.我不敢相信我是唯一一个认为报告过滤器没有过滤数据透视源很愚蠢的人,这对我来说似乎是合乎逻辑的。

Many thanks,非常感谢,

Demo file 演示文件

You can use the below code to generate a separate sheet for each country.您可以使用以下代码为每个国家/地区生成单独的工作表。 This creates sheets similar to "show report filter pages", but pastes data as plain text.这将创建类似于“显示报告过滤器页面”的工作表,但将数据粘贴为纯文本。

This is based on the sample sheet provided and if sheets with same name alrady exist it doesn't work right now.这是基于提供的样本表,如果已经存在同名的表,它现在不起作用。 But you can add a condition to check the same但是你可以添加一个条件来检查相同的

Sub SplitPivot()

Set pvtTable = Worksheets("pivot").PivotTables("PivotTable47")

For Each pvtitem In pvtTable.PivotFields("countries").PivotItems

    pvtTable.PivotFields("countries"). _
        ClearAllFilters
    pvtTable.PivotFields("countries").CurrentPage = pvtitem.Name
    Application.CutCopyMode = False
    pvtTable.PivotSelect "", xlDataAndLabel, True
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ' Sheets("Sheet5").Select
    ActiveSheet.Name = pvtitem.Name
    
    MsgBox pvtitem.Name & " Done"
        
Next

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM