Skip to content

Commit

Permalink
Updated documentation for sanitize_powerbi_report function
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilannan committed Nov 23, 2024
1 parent 9628f49 commit 40db0d2
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 4 deletions.
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
## Improvements:
Report Wireframe page sorting corrected.
## New Function
`sanitize_powerbi_report`: A comprehensive Power BI report sanitization utility designed to clean up and optimize Power BI reports.

### Cleanup Actions
- Remove unused measures
- Clean up unused bookmarks
- Remove unused custom visuals
- Disable "Show items with no data"
- Hide tooltip and drillthrough pages
- Set the first page as active
- Remove empty pages
- Remove hidden visuals never shown
- Clean up invalid bookmarks

### Key Benefits
- Reduces report file size
- Improves report performance
- Cleans up unused and hidden elements
- Provides granular control over report cleanup

### Usage
Refer to [example_usage.ipynb](examples/example_usage.ipynb) for detailed usage instructions and examples of the report sanitization function.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pbir-utils is a python project designed to streamline the tasks that Power BI de
- **Get Measure Dependencies**: Extract the dependency tree for report-level measures.
- **Update Report Level Filters**: Update the filters added to the Power BI report level filter pane.
- **Sort Report Level Filters**: Reorder filters in report filter pane on a specified sorting strategy.
- **Sanitize Power BI Report**: Clean up and optimize Power BI reports.

## Installation
```python
Expand Down
94 changes: 94 additions & 0 deletions examples/example_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,100 @@
" custom_order=None,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example 8: Sanitize PBIR Report\n",
"Thes function is a powerful utility designed to clean up and optimize Power BI reports by performing various sanitization actions. It helps remove unnecessary components, improve report performance, and maintain a clean report structure.\n",
"\n",
"## Parameters\n",
"\n",
"### `report_path` (str): The file system path to the folder containing the PowerBI report.\n",
"\n",
"### `actions` (list[str]): A list of sanitization actions to perform on the report.\n",
"- **Available Actions**:\n",
" 1. `\"remove_unused_measures\"`: \n",
" - Removes measures that are not used in any visuals either directly or indirectly through measure dependencies.\n",
" - Helps reduce report complexity and improve performance.\n",
"\n",
" 2. `\"remove_unused_bookmarks\"`: \n",
" - Removes bookmarks that are not activated through bookmark navigators or actions.\n",
" - Cleans up unused bookmark configurations.\n",
"\n",
" 3. `\"remove_unused_custom_visuals\"`: \n",
" - Removes custom visuals that are not used in the report.\n",
" - Reduces report file size and potential performance overhead.\n",
"\n",
" 4. `\"disable_show_items_with_no_data\"`: \n",
" - Disables the \"Show items with no data\" option for all visuals.\n",
" - Helps improve visual performance.\n",
"\n",
" 5. `\"hide_tooltip_drillthrough_pages\"`: \n",
" - Hides tooltip and drillthrough pages from the report view.\n",
" - Keeps the main report clean and focused.\n",
"\n",
" 6. `\"set_first_page_as_active\"`: \n",
" - Sets the first page of the report as the default active page.\n",
" - Ensures a consistent initial view when opening the report.\n",
"\n",
" 7. `\"remove_empty_pages\"`: \n",
" - Removes pages that do not contain any visuals.\n",
" - Streamlines the report structure.\n",
"\n",
" 8. `\"remove_hidden_visuals_never_shown\"`: \n",
" - Removes visuals and groups that are permanently hidden and never displayed.\n",
" - Reduces report complexity with rougue visuals.\n",
"\n",
" 9. `\"cleanup_invalid_bookmarks\"`: \n",
" - Removes bookmarks referencing non-existent pages or visuals.\n",
" - Ensures bookmark integrity and prevents potential errors.\n",
"\n",
"- **Example**: \n",
" ```python\n",
" pbir.sanitize_powerbi_report(\n",
" r\"C:\\DEV\\MyReport.Report\", \n",
" [\n",
" \"remove_unused_measures\", \n",
" \"hide_tooltip_drillthrough_pages\", \n",
" \"remove_hidden_visuals_never_shown\"\n",
" ]\n",
" )\n",
" ```\n",
"\n",
"## Behavior\n",
"- The function processes each specified action sequentially.\n",
"- If an unknown action is provided, it will be skipped with a warning message.\n",
"- Actions are independent and can be combined as needed.\n",
"\n",
"## Warnings and Considerations\n",
"- Always backup your report or have it under version control before running sanitization.\n",
"- Some actions are irreversible and will permanently remove report components.\n",
"- Test the sanitized report thoroughly to ensure no critical functionality is lost."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pbir.sanitize_powerbi_report(\n",
" r\"C:\\DEV\\git\\Fabric-Cricsheet\\Power BI Report\\Cricsheet Analysis.Report\",\n",
" [\n",
" \"cleanup_invalid_bookmarks\",\n",
" \"remove_unused_measures\",\n",
" \"remove_unused_bookmarks\",\n",
" \"remove_unused_custom_visuals\",\n",
" \"disable_show_items_with_no_data\",\n",
" \"hide_tooltip_drillthrough_pages\",\n",
" \"set_first_page_as_active\",\n",
" \"remove_empty_pages\",\n",
" \"remove_hidden_visuals_never_shown\",\n",
" ],\n",
")"
]
}
],
"metadata": {
Expand Down
6 changes: 4 additions & 2 deletions src/pbir_utils/pbir_report_sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,12 @@ def _check_bookmark(bookmark_data: dict, _: str) -> tuple[set, set]:
),
None,
)

if folder and os.path.exists(folder):
# Remove visual interactions for the visual
page_json_path = os.path.join(os.path.dirname(os.path.dirname(folder)), "page.json")
page_json_path = os.path.join(
os.path.dirname(os.path.dirname(folder)), "page.json"
)
if os.path.exists(page_json_path):
page_data = _load_json(page_json_path)
visual_interactions = page_data.get("visualInteractions", [])
Expand Down

0 comments on commit 40db0d2

Please sign in to comment.