pbir-utils 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pbir_utils-0.0.0/.github/workflows/python-publish.yml +47 -0
- pbir_utils-0.0.0/.gitignore +66 -0
- pbir_utils-0.0.0/PKG-INFO +41 -0
- pbir_utils-0.0.0/README.md +24 -0
- pbir_utils-0.0.0/examples/example_usage.ipynb +298 -0
- pbir_utils-0.0.0/pyproject.toml +31 -0
- pbir_utils-0.0.0/setup.cfg +4 -0
- pbir_utils-0.0.0/src/pbir_utils/__init__.py +14 -0
- pbir_utils-0.0.0/src/pbir_utils/json_utils.py +40 -0
- pbir_utils-0.0.0/src/pbir_utils/metadata_extractor.py +343 -0
- pbir_utils-0.0.0/src/pbir_utils/pbir_measure_utils.py +290 -0
- pbir_utils-0.0.0/src/pbir_utils/pbir_processor.py +275 -0
- pbir_utils-0.0.0/src/pbir_utils/report_wireframe_visualizer.py +292 -0
- pbir_utils-0.0.0/src/pbir_utils/visual_interactions_utils.py +245 -0
- pbir_utils-0.0.0/src/pbir_utils.egg-info/PKG-INFO +41 -0
- pbir_utils-0.0.0/src/pbir_utils.egg-info/SOURCES.txt +17 -0
- pbir_utils-0.0.0/src/pbir_utils.egg-info/dependency_links.txt +1 -0
- pbir_utils-0.0.0/src/pbir_utils.egg-info/requires.txt +2 -0
- pbir_utils-0.0.0/src/pbir_utils.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Publish Python Package and Create Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- '*.*.*'
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
contents: write
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout code
|
|
16
|
+
uses: actions/checkout@v3
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- name: Set up Python
|
|
21
|
+
uses: actions/setup-python@v4
|
|
22
|
+
with:
|
|
23
|
+
python-version: '3.x'
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: |
|
|
27
|
+
python -m pip install --upgrade pip
|
|
28
|
+
pip install build twine setuptools-scm
|
|
29
|
+
|
|
30
|
+
- name: Build package
|
|
31
|
+
run: python -m build
|
|
32
|
+
|
|
33
|
+
- name: Publish package
|
|
34
|
+
env:
|
|
35
|
+
TWINE_USERNAME: __token__
|
|
36
|
+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
|
37
|
+
run: python -m twine upload dist/*
|
|
38
|
+
|
|
39
|
+
- name: Create GitHub Release
|
|
40
|
+
uses: softprops/action-gh-release@v1
|
|
41
|
+
with:
|
|
42
|
+
name: pbir-utils ${{ github.ref_name }}
|
|
43
|
+
body: |
|
|
44
|
+
## Renamed Function:
|
|
45
|
+
- *get_measure_dependencies* renamed to **generate_measure_dependencies_report**
|
|
46
|
+
draft: false
|
|
47
|
+
prerelease: false
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
*.egg-info/
|
|
24
|
+
.installed.cfg
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# PyInstaller
|
|
28
|
+
*.manifest
|
|
29
|
+
*.spec
|
|
30
|
+
|
|
31
|
+
# Installer logs
|
|
32
|
+
pip-log.txt
|
|
33
|
+
pip-delete-this-directory.txt
|
|
34
|
+
|
|
35
|
+
# Unit test / coverage reports
|
|
36
|
+
htmlcov/
|
|
37
|
+
.tox/
|
|
38
|
+
.coverage
|
|
39
|
+
.coverage.*
|
|
40
|
+
.cache
|
|
41
|
+
nosetests.xml
|
|
42
|
+
coverage.xml
|
|
43
|
+
*.cover
|
|
44
|
+
.hypothesis/
|
|
45
|
+
.pytest_cache/
|
|
46
|
+
|
|
47
|
+
# Jupyter Notebook
|
|
48
|
+
.ipynb_checkpoints
|
|
49
|
+
|
|
50
|
+
# pyenv
|
|
51
|
+
.python-version
|
|
52
|
+
|
|
53
|
+
# Environment
|
|
54
|
+
.env
|
|
55
|
+
.venv
|
|
56
|
+
env/
|
|
57
|
+
venv/
|
|
58
|
+
ENV/
|
|
59
|
+
|
|
60
|
+
# IDE settings
|
|
61
|
+
.vscode/
|
|
62
|
+
.idea/
|
|
63
|
+
|
|
64
|
+
# Project-specific
|
|
65
|
+
*.csv
|
|
66
|
+
*.json
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pbir-utils
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: A tool for managing Power BI Enhanced Report Format (PBIR) projects
|
|
5
|
+
Author: Akhil Ashok
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Homepage, https://github.com/akhilannan/pbir-utils
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Intended Audience :: Education
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
Requires-Dist: dash
|
|
16
|
+
Requires-Dist: plotly
|
|
17
|
+
|
|
18
|
+
# PBIR Utilities
|
|
19
|
+
|
|
20
|
+
pbir-utils is a python project designed to streamline the tasks that Power BI developers typically handle manually in Power BI Desktop. This module offers a range of utility functions to efficiently manage and manipulate PBIR metadata.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **Extract Metadata**: Retrieve key metadata informations from PBIR files.
|
|
25
|
+
- **Update Metadata**: Apply updates to metadata within PBIR files.
|
|
26
|
+
- **Report Wireframe Visualizer**: Visualize PBIR report wireframe.
|
|
27
|
+
- **Disable Visual Interactions**: Bulk disable interactions in PBIR report.
|
|
28
|
+
- **Remove Measures**: Bulk remove report-level measures.
|
|
29
|
+
- **Get Measure Dependencies**: Extract the dependency tree for report-level measures.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
```python
|
|
33
|
+
pip install pbir-utils
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
Once installed, you can import the library as follows:
|
|
38
|
+
```python
|
|
39
|
+
import pbir_utils as pbir
|
|
40
|
+
```
|
|
41
|
+
To get started, refer to [example_usage.ipynb](examples/example_usage.ipynb) notebook, which contains detailed examples demonstrating how to use the various functions available in pbir_utils.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# PBIR Utilities
|
|
2
|
+
|
|
3
|
+
pbir-utils is a python project designed to streamline the tasks that Power BI developers typically handle manually in Power BI Desktop. This module offers a range of utility functions to efficiently manage and manipulate PBIR metadata.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Extract Metadata**: Retrieve key metadata informations from PBIR files.
|
|
8
|
+
- **Update Metadata**: Apply updates to metadata within PBIR files.
|
|
9
|
+
- **Report Wireframe Visualizer**: Visualize PBIR report wireframe.
|
|
10
|
+
- **Disable Visual Interactions**: Bulk disable interactions in PBIR report.
|
|
11
|
+
- **Remove Measures**: Bulk remove report-level measures.
|
|
12
|
+
- **Get Measure Dependencies**: Extract the dependency tree for report-level measures.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
```python
|
|
16
|
+
pip install pbir-utils
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
Once installed, you can import the library as follows:
|
|
21
|
+
```python
|
|
22
|
+
import pbir_utils as pbir
|
|
23
|
+
```
|
|
24
|
+
To get started, refer to [example_usage.ipynb](examples/example_usage.ipynb) notebook, which contains detailed examples demonstrating how to use the various functions available in pbir_utils.
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "markdown",
|
|
5
|
+
"metadata": {},
|
|
6
|
+
"source": [
|
|
7
|
+
"# Install dependencies"
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"cell_type": "code",
|
|
12
|
+
"execution_count": null,
|
|
13
|
+
"metadata": {},
|
|
14
|
+
"outputs": [],
|
|
15
|
+
"source": [
|
|
16
|
+
"!pip install --upgrade pbir-utils -q"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"cell_type": "markdown",
|
|
21
|
+
"metadata": {},
|
|
22
|
+
"source": [
|
|
23
|
+
"# Import Libraries"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"cell_type": "code",
|
|
28
|
+
"execution_count": null,
|
|
29
|
+
"metadata": {},
|
|
30
|
+
"outputs": [],
|
|
31
|
+
"source": [
|
|
32
|
+
"import pbir_utils as pbir"
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"cell_type": "markdown",
|
|
37
|
+
"metadata": {},
|
|
38
|
+
"source": [
|
|
39
|
+
"# Initialize Path Variables"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"cell_type": "code",
|
|
44
|
+
"execution_count": null,
|
|
45
|
+
"metadata": {},
|
|
46
|
+
"outputs": [],
|
|
47
|
+
"source": [
|
|
48
|
+
"pbip_directory = r\"C:\\DEV\\Power BI Report\"\n",
|
|
49
|
+
"csv_path = r\"C:\\DEV\\Attribute_Mapping.csv\"\n",
|
|
50
|
+
"output_csv_path = r\"C:\\DEV\\output.csv\"\n",
|
|
51
|
+
"pbir_report_folder = r'C:\\DEV\\Power BI Report\\Report Name.Report'"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"cell_type": "markdown",
|
|
56
|
+
"metadata": {},
|
|
57
|
+
"source": [
|
|
58
|
+
"# Example 1: Batch update attributes in PBIR project\n",
|
|
59
|
+
"Performs a batch update on all components of a Power BI Enhanced Report Format (PBIR) project by processing JSON files in the specified directory. This function updates table and column references in PBIR files based on mappings provided in a CSV file. It is designed to handle the PBIR folder structure where report components are divided into individual JSON files.\n",
|
|
60
|
+
"\n",
|
|
61
|
+
"**Parameters:**\n",
|
|
62
|
+
"- `directory_path` (str): The path to the root directory of the PBIR project (typically the 'definition' folder). This directory should contain all the JSON files representing different components of the PBIR project.\n",
|
|
63
|
+
"- `csv_path` (str): The path to the `Attribute_Mapping.csv` file that contains mappings for updating table and column names. This CSV file should include the following columns:\n",
|
|
64
|
+
"\n",
|
|
65
|
+
" - `old_tbl`: Old table names\n",
|
|
66
|
+
" - `old_col`: Old column names\n",
|
|
67
|
+
" - `new_tbl`: New table names (optional if the table name is unchanged)\n",
|
|
68
|
+
" - `new_col`: New column names\n",
|
|
69
|
+
"\n",
|
|
70
|
+
" The `Attribute_Mapping.csv` file should be formatted as follows:\n",
|
|
71
|
+
"\n",
|
|
72
|
+
" | old_tbl | old_col | new_tbl | new_col |\n",
|
|
73
|
+
" |-----------|-----------------|------------|----------------|\n",
|
|
74
|
+
" | Sale | sale_id | Sales | Sale Id |\n",
|
|
75
|
+
" | Sale | order_date | Sales | OrderDate |\n",
|
|
76
|
+
" | Date | | Dates | |\n",
|
|
77
|
+
" | Product | product_name | | Product Name |\n",
|
|
78
|
+
" | Product | product_id | | Product ID |\n",
|
|
79
|
+
"\n",
|
|
80
|
+
" This format enables you to document changes to table and column names within the Semantic Model. If a table name remains unchanged, specifying `new_tbl` is optional. Similarly, if only the table name has changed but the column names remain the same, you do not need to specify `old_col` and `new_col`."
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"cell_type": "code",
|
|
85
|
+
"execution_count": null,
|
|
86
|
+
"metadata": {},
|
|
87
|
+
"outputs": [],
|
|
88
|
+
"source": [
|
|
89
|
+
"pbir.batch_update_pbir_project(pbip_directory, csv_path)"
|
|
90
|
+
]
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"cell_type": "markdown",
|
|
94
|
+
"metadata": {},
|
|
95
|
+
"source": [
|
|
96
|
+
"# Example 2: Export attribute metadata to CSV\n",
|
|
97
|
+
"Exports metadata from Power BI Enhanced Report Format (PBIR) into a CSV file. The function processes JSON files within a specified directory to extract detailed information about tables, columns, measures, their DAX expressions, and their usage contexts. It consolidates this information and writes it to a CSV file, which provides a structured view of the PBIR report's metadata.\n",
|
|
98
|
+
"\n",
|
|
99
|
+
"**Parameters:**\n",
|
|
100
|
+
"- `directory_path` (str): The path to the directory containing PBIR JSON files to be processed. You can even specify a parent folder that includes multiple reports within its subdirectories.\n",
|
|
101
|
+
"- `csv_output_path` (str): The path where the output CSV file will be saved."
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"cell_type": "code",
|
|
106
|
+
"execution_count": null,
|
|
107
|
+
"metadata": {},
|
|
108
|
+
"outputs": [],
|
|
109
|
+
"source": [
|
|
110
|
+
"pbir.export_pbir_metadata_to_csv(\n",
|
|
111
|
+
" directory_path=pbip_directory, \n",
|
|
112
|
+
" csv_output_path=output_csv_path\n",
|
|
113
|
+
")"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"cell_type": "markdown",
|
|
118
|
+
"metadata": {},
|
|
119
|
+
"source": [
|
|
120
|
+
"# Example 3: Display Report Wireframe\n",
|
|
121
|
+
"The function generates and displays interactive wireframes for a report using Dash and Plotly. This function visualizes the layout of pages and their visual components.\n",
|
|
122
|
+
"\n",
|
|
123
|
+
"### Parameters:\n",
|
|
124
|
+
"- **`root_folder` (str)**: The path to the root folder of the PBIR report. This folder should contain the `definition/pages` subfolder where the JSON files for pages and visuals are located.\n",
|
|
125
|
+
"\n",
|
|
126
|
+
"- **`pages` (list, optional)**: A list of page names to include in the wireframe visualization. If this list is empty or not provided, all pages will be included. For example: `pages=['Overview', 'Detail']`.\n",
|
|
127
|
+
"\n",
|
|
128
|
+
"- **`visual_types` (list, optional)**: A list of visual types to include in the visualization. Visuals not matching these types will be excluded. If this list is empty or not provided, all visual types will be included. For example: `visual_types=['slicer', 'tableEx']`.\n",
|
|
129
|
+
"\n",
|
|
130
|
+
"- **`visual_ids` (list, optional)**: A list of visual IDs to include. Only visuals with these IDs will be displayed. If this list is empty or not provided, all visuals will be included. For example: `visual_ids=['f0a86ce15d6071a24950', '0b80818ed5eede98baa8']`.\n",
|
|
131
|
+
"\n",
|
|
132
|
+
"- **`show_hidden` (bool, optional)**: Determines whether to display hidden visuals. Set to `True` to show hidden visuals, or `False` to exclude them. Default is `True`.\n",
|
|
133
|
+
"\n",
|
|
134
|
+
"### Behavior:\n",
|
|
135
|
+
"The `pages`, `visual_types`, and `visual_ids` parameters work with an AND logic, meaning that only visuals matching all specified criteria will be shown. For example, setting `pages=['Overview']` and `visual_types=['slicer']` will display only `slicer` visuals on the `Overview` page.\n"
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"cell_type": "code",
|
|
140
|
+
"execution_count": null,
|
|
141
|
+
"metadata": {},
|
|
142
|
+
"outputs": [],
|
|
143
|
+
"source": [
|
|
144
|
+
"pbir.display_report_wireframes(\n",
|
|
145
|
+
" report_path=pbir_report_folder,\n",
|
|
146
|
+
" pages=[],\n",
|
|
147
|
+
" visual_types=[],\n",
|
|
148
|
+
" visual_ids=[],\n",
|
|
149
|
+
" show_hidden=True\n",
|
|
150
|
+
")"
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"cell_type": "markdown",
|
|
155
|
+
"metadata": {},
|
|
156
|
+
"source": [
|
|
157
|
+
"# Example 4: Disable Visual Interactions\n",
|
|
158
|
+
"This function disables interactions between visuals based on the provided parameters.\n",
|
|
159
|
+
"\n",
|
|
160
|
+
"### Parameters:\n",
|
|
161
|
+
"\n",
|
|
162
|
+
"- **`report_path` (str)**: The path to the root folder of the PBIR report.\n",
|
|
163
|
+
"\n",
|
|
164
|
+
"- **`pages` (list, optional)**: List of page names to process. If not provided, all pages will be processed. For example: `pages=['Overview']`.\n",
|
|
165
|
+
"\n",
|
|
166
|
+
"- **`source_visual_ids` (list, optional)**: List of specific source visual IDs. If not provided, all visuals will be used as sources. For example: `source_visual_ids=['f0a86ce15d6071a24950', '0b80818ed5eede98baa8']`.\n",
|
|
167
|
+
"\n",
|
|
168
|
+
"- **`source_visual_types` (list, optional)**: List of source visual types. If not provided, all visuals will be used as sources. For example: `source_visual_types=['slicer']`.\n",
|
|
169
|
+
"\n",
|
|
170
|
+
"- **`target_visual_ids` (list, optional)**: List of specific target visual IDs. If not provided, all visuals will be used as targets. For example: `target_visual_ids=['p05f7ce15d6071a24950']`.\n",
|
|
171
|
+
"\n",
|
|
172
|
+
"- **`target_visual_types` (list, optional)**: List of target visual types. If not provided, all visuals will be used as targets. For example: `target_visual_types=['tableEx']`.\n",
|
|
173
|
+
"\n",
|
|
174
|
+
"- **`update_type` (str, optional)**: Determines how interactions are managed. Options include:\n",
|
|
175
|
+
" - **`\"Upsert\"`**: Disables any existing interactions that match the specified source/target parameters and inserts new combinations. Interactions not part of the specified source/target parameters will remain unchanged. This is the *default option*.\n",
|
|
176
|
+
" - **`\"Insert\"`**: Inserts new interactions based on the source/target parameters without modifying existing interactions.\n",
|
|
177
|
+
" - **`\"Overwrite\"`**: Replaces all existing interactions with the new ones that match the specified source/target parameters, removing any interactions not part of the new configuration.\n",
|
|
178
|
+
"\n",
|
|
179
|
+
"### Behavior:\n",
|
|
180
|
+
"\n",
|
|
181
|
+
"1. **If Only `report_path` Is Provided:**\n",
|
|
182
|
+
" - The function will disable interactions between all visuals across all pages in the report. This means that no visuals on any page will interact with each other.\n",
|
|
183
|
+
"\n",
|
|
184
|
+
"2. **If `report_path` and `pages` Are Provided:**\n",
|
|
185
|
+
" - The function will disable interactions between all visuals but only on the specified pages. Visuals on pages not listed will remain unaffected.\n",
|
|
186
|
+
"\n",
|
|
187
|
+
"3. **If `source_visual_ids` or `source_visual_types` Are Provided:**\n",
|
|
188
|
+
" - The function will disable interactions from the specified source visuals (IDs or types) to all other visuals (targets) on the pages specified. For example, if `source_visual_ids` includes `['p05f7ce15d6071a24950']`, interactions involving `p05f7ce15d6071a24950` to all other visuals (or specified target visuals/types) will be disabled on the page.\n",
|
|
189
|
+
"\n",
|
|
190
|
+
"4. **If `target_visual_ids` or `target_visual_types` Are Provided:**\n",
|
|
191
|
+
" - The function will disable interactions from all source visuals to the specified target visuals. For instance, if `target_visual_ids` includes `['f0a86ce15d6071a24950']`, interactions from all source visuals (or specified source visuals/types) to `f0a86ce15d6071a24950` will be disabled on the page."
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"cell_type": "code",
|
|
196
|
+
"execution_count": null,
|
|
197
|
+
"metadata": {},
|
|
198
|
+
"outputs": [],
|
|
199
|
+
"source": [
|
|
200
|
+
"pbir.disable_visual_interactions(\n",
|
|
201
|
+
" report_path=pbir_report_folder,\n",
|
|
202
|
+
" pages=[],\n",
|
|
203
|
+
" source_visual_ids=[],\n",
|
|
204
|
+
" source_visual_types=[],\n",
|
|
205
|
+
" target_visual_ids=[],\n",
|
|
206
|
+
" target_visual_types=[],\n",
|
|
207
|
+
" update_type=\"Upsert\"\n",
|
|
208
|
+
")"
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"cell_type": "markdown",
|
|
213
|
+
"metadata": {},
|
|
214
|
+
"source": [
|
|
215
|
+
"# Example 4: Remove report level Measures\n",
|
|
216
|
+
"This function scans through a Power BI PBIR Report and removes report-level measures. It can remove all measures or a specified list of measures, with an option to check if the measures are used in any visuals before removal.\n",
|
|
217
|
+
"\n",
|
|
218
|
+
"## Parameters\n",
|
|
219
|
+
"\n",
|
|
220
|
+
"- **`report_path` (str)**: The file system path to the folder containing the PowerBI report.\n",
|
|
221
|
+
"\n",
|
|
222
|
+
"- **`measure_names` (Optional[list])**: A list of measure names that you want to remove from the report. **If this parameter is `None` or an empty list, all measures in the report will be considered for removal**. \n",
|
|
223
|
+
"\n",
|
|
224
|
+
"- **`check_visual_usage` (bool)**: A flag indicating whether to only remove measures that are not used in any visuals within the report.\n",
|
|
225
|
+
" - **True**: Only remove a measure if neither the measure itself nor any of its dependent measures are used in any visuals. (default behavior if not specified)\n",
|
|
226
|
+
" - **False**: Measures will be removed regardless of their usage in visuals."
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"cell_type": "code",
|
|
231
|
+
"execution_count": null,
|
|
232
|
+
"metadata": {},
|
|
233
|
+
"outputs": [],
|
|
234
|
+
"source": [
|
|
235
|
+
"pbir.remove_measures(\n",
|
|
236
|
+
" report_path=pbir_report_folder, \n",
|
|
237
|
+
" measure_names=[], \n",
|
|
238
|
+
" check_visual_usage=True\n",
|
|
239
|
+
")"
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"cell_type": "markdown",
|
|
244
|
+
"metadata": {},
|
|
245
|
+
"source": [
|
|
246
|
+
"# Example 5: Generate measure dependencies report\n",
|
|
247
|
+
"This function generates a dependency tree for measures in a Power BI report, *focusing only on measures that have dependencies on other measures*. \n",
|
|
248
|
+
"\n",
|
|
249
|
+
"## Parameters\n",
|
|
250
|
+
"\n",
|
|
251
|
+
"- **`report_path` (str)**: The file system path to the folder containing the PowerBI report.\n",
|
|
252
|
+
"\n",
|
|
253
|
+
"- **`measure_names` (Optional[list])**: \n",
|
|
254
|
+
" - This is an optional list of measure names that you want to analyze. \n",
|
|
255
|
+
" - If you pass a list of measure names, the function will only analyze the dependencies for those specific measures.\n",
|
|
256
|
+
" - If you pass `None` (default) or an empty list `[]`, the function will analyze all measures in the report.\n",
|
|
257
|
+
"\n",
|
|
258
|
+
"- **`include_visual_ids` (bool)**: This boolean flag determines whether to include the IDs of visuals that use the measures being analyzed.\n",
|
|
259
|
+
" - **True**: The function will append the visual IDs in square brackets after each measure in the dependency tree.\n",
|
|
260
|
+
" - **False**: Visual IDs will be excluded (default behavior if not specified)"
|
|
261
|
+
]
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"cell_type": "code",
|
|
265
|
+
"execution_count": null,
|
|
266
|
+
"metadata": {},
|
|
267
|
+
"outputs": [],
|
|
268
|
+
"source": [
|
|
269
|
+
"print(\n",
|
|
270
|
+
" pbir.generate_measure_dependencies_report(\n",
|
|
271
|
+
" report_path=pbir_report_folder, measure_names=[], include_visual_ids=True\n",
|
|
272
|
+
" )\n",
|
|
273
|
+
")"
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
"metadata": {
|
|
278
|
+
"kernelspec": {
|
|
279
|
+
"display_name": ".venv",
|
|
280
|
+
"language": "python",
|
|
281
|
+
"name": "python3"
|
|
282
|
+
},
|
|
283
|
+
"language_info": {
|
|
284
|
+
"codemirror_mode": {
|
|
285
|
+
"name": "ipython",
|
|
286
|
+
"version": 3
|
|
287
|
+
},
|
|
288
|
+
"file_extension": ".py",
|
|
289
|
+
"mimetype": "text/x-python",
|
|
290
|
+
"name": "python",
|
|
291
|
+
"nbconvert_exporter": "python",
|
|
292
|
+
"pygments_lexer": "ipython3",
|
|
293
|
+
"version": "3.12.5"
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
"nbformat": 4,
|
|
297
|
+
"nbformat_minor": 2
|
|
298
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel", "setuptools-scm"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pbir-utils"
|
|
7
|
+
description = "A tool for managing Power BI Enhanced Report Format (PBIR) projects"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = {text = "MIT License"}
|
|
10
|
+
authors = [
|
|
11
|
+
{name = "Akhil Ashok"}
|
|
12
|
+
]
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Intended Audience :: Education",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent"
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"dash",
|
|
23
|
+
"plotly",
|
|
24
|
+
]
|
|
25
|
+
dynamic = ["version"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/akhilannan/pbir-utils"
|
|
29
|
+
|
|
30
|
+
[tool.setuptools]
|
|
31
|
+
packages = {find = {where = ["src"]}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .pbir_processor import batch_update_pbir_project
|
|
2
|
+
from .metadata_extractor import export_pbir_metadata_to_csv
|
|
3
|
+
from .report_wireframe_visualizer import display_report_wireframes
|
|
4
|
+
from .visual_interactions_utils import disable_visual_interactions
|
|
5
|
+
from .pbir_measure_utils import remove_measures, generate_measure_dependencies_report
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"batch_update_pbir_project",
|
|
9
|
+
"export_pbir_metadata_to_csv",
|
|
10
|
+
"display_report_wireframes",
|
|
11
|
+
"disable_visual_interactions",
|
|
12
|
+
"remove_measures",
|
|
13
|
+
"generate_measure_dependencies_report",
|
|
14
|
+
]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _load_json(file_path: str) -> dict:
|
|
5
|
+
"""
|
|
6
|
+
Loads and returns the content of a JSON file.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
file_path (str): Path to the JSON file.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
dict: Parsed JSON data.
|
|
13
|
+
|
|
14
|
+
Raises:
|
|
15
|
+
json.JSONDecodeError: If the JSON cannot be parsed.
|
|
16
|
+
IOError: If the file cannot be read.
|
|
17
|
+
"""
|
|
18
|
+
try:
|
|
19
|
+
with open(file_path, "r", encoding="utf-8") as file:
|
|
20
|
+
return json.load(file)
|
|
21
|
+
except json.JSONDecodeError:
|
|
22
|
+
print(f"Error: Unable to parse JSON in file: {file_path}")
|
|
23
|
+
except IOError as e:
|
|
24
|
+
print(f"Error: Unable to read or write file: {file_path}. {str(e)}")
|
|
25
|
+
return {}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _write_json(file_path: str, data: dict) -> None:
|
|
29
|
+
"""
|
|
30
|
+
Write JSON data to a file with indentation.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
file_path (str): The path to the file where JSON data will be written.
|
|
34
|
+
data (dict): The JSON data to be written to the file.
|
|
35
|
+
|
|
36
|
+
Returns:
|
|
37
|
+
None
|
|
38
|
+
"""
|
|
39
|
+
with open(file_path, "w", encoding="utf-8") as file:
|
|
40
|
+
json.dump(data, file, indent=2)
|