Metadata-Version: 2.4
Name: pbi-audit
Version: 0.2.0
Summary: Audit DAX measures in a Power BI PBIP project
Author: jliezed
License: MIT
Project-URL: Homepage, https://github.com/jliezed/pbi-audit
Project-URL: Repository, https://github.com/jliezed/pbi-audit
Keywords: powerbi,dax,pbip,audit,measures
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openpyxl
Dynamic: license-file

# pbi-audit

> Audit every DAX measure in your Power BI project — find what's unused, what's a helper, and what's actually powering your visuals.

[![PyPI version](https://img.shields.io/pypi/v/pbi-audit.svg)](https://pypi.org/project/pbi-audit/)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

---

## Prerequisite — save your report as a PBIP project

`pbi-audit` reads the open file format that Power BI Desktop writes when you save as a **PBIP project** (as opposed to the legacy `.pbix` binary).

To enable it:
1. Open Power BI Desktop
2. Go to **File → Options → Preview features**
3. Enable **Power BI Project (.pbip)**
4. Save your report: **File → Save as** and choose the `.pbip` format

This produces a folder structure that `pbi-audit` can read. `.pbix` files are not supported.

---

## What it does

Power BI projects accumulate measures over time. `pbi-audit` scans your PBIP project and classifies every single measure:

| Status | Meaning |
|---|---|
| `UNUSED` | Not referenced anywhere — safe to delete |
| `USED (DAX only)` | Only called by other measures — a helper |
| `USED (Visual only)` | Directly driving a visual on a report page |
| `USED (Visual + DAX)` | Used in both visuals and other measures |

It then generates an **HTML report** and/or an **Excel workbook** so you can review, filter, and act.

---

## Quick start

```bash
pip install pbi-audit
pbi-audit
```

That's it. A guided wizard walks you through the rest.

---

## Demo


Wizard walkthrough (text preview):

```
╔══════════════════════════════════════════════════════╗
║  pbi-audit  v0.1.0                                   ║
║                                                      ║
║  Audit DAX measures in a Power BI PBIP project.      ║
║  Scans your semantic model and report pages to       ║
║  classify every measure as:                          ║
║                                                      ║
║    UNUSED          — safe to delete                  ║
║    USED (DAX only) — helper/intermediate measure     ║
║    USED (Visual)   — directly used in a report       ║
║    USED (Both)     — used in visuals and DAX         ║
║                                                      ║
║  Outputs an HTML and/or Excel report.                ║
╚══════════════════════════════════════════════════════╝

  Step 1/3 — PBIP Project Folder
  ────────────────────────────────────────────────────
  Type a path, or press Enter to open the folder browser:

  > C:\Projects\Store Sales

  ✓ Folder: C:\Projects\Store Sales

  Step 2/3 — Output Folder
  ────────────────────────────────────────────────────
  Where should reports be saved?
  Press Enter to save in the PBIP folder, type a path, or type "o" to browse:

  > 

  ✓ Output: C:\Projects\Store Sales

  Step 3/3 — Report Format
  ────────────────────────────────────────────────────
  [1] HTML + Excel  (default)
  [2] HTML only
  [3] Excel only

  > 1

  ✓ Format: both

  Running audit
  ────────────────────────────────────────────────────
  ✓ 42 measures found
  ✓ 18 measures referenced in visuals
  ✓ Usage status computed

  Results
  ────────────────────────────────────────────────────
    UNUSED          11
    USED (DAX only)  8
    USED (Visual)    9
    USED (Both)     14
    ────────────────
    Total           42

  Saving reports
  ────────────────────────────────────────────────────
  ✓ HTML  → C:\Projects\Store Sales\DAX_Measures_Audit.html
  ✓ Excel → C:\Projects\Store Sales\DAX_Measures_Audit.xlsx

  Done! Open the report(s) above to explore your measures.
```

---

## Report preview

![HTML report preview](https://raw.githubusercontent.com/jliezed/pbi-audit/main/docs/report_html_preview.png)

> Run `pbi-audit` against your project to generate the interactive HTML report — filter by status, search by measure name, and hover any formula to see the full DAX expression.

---

## Installation

Requires Python 3.9 or later.

```bash
pip install pbi-audit
```

---

## Usage

### Guided wizard (recommended)

Run with no arguments — a step-by-step wizard will prompt for your PBIP folder, output location, and report format:

```bash
pbi-audit
```

### Direct path

```bash
pbi-audit "C:\path\to\your_project.pbip"
```

### Options

| Argument | Short | Description | Default |
|---|---|---|---|
| `path` | | Path to the PBIP project root | opens wizard |
| `--output` | `-o` | Where to save the reports | same as input |
| `--format` | `-f` | `html`, `excel`, or `both` | `both` |

### Examples

```bash
# Audit a specific project, HTML report only
pbi-audit "C:\Projects\Sales.pbip" --format html

# Save reports to a separate folder
pbi-audit "C:\Projects\Sales.pbip" -o "C:\Reports"
```

---

## Output

Two files are written to the output folder:

**`DAX_Measures_Audit.html`**
Interactive table with status filters, table filter, and search. Hover any formula cell to see the full DAX expression.

**`DAX_Measures_Audit.xlsx`**
Excel workbook with a Summary sheet (counts by status) and a Measures sheet with full detail, auto-filter, and frozen header.

---

## Expected project structure

`pbi-audit` works with the standard PBIP layout produced by Power BI Desktop:

```
my_project/
├── my_project.SemanticModel/
│   └── definition/
│       └── tables/
│           └── *.tmdl
└── my_project.Report/
    └── definition/
        └── pages/
            └── */
                ├── page.json
                └── visuals/
                    └── */
                        └── visual.json
```

---

## Contributing

Bug reports and feature requests are welcome — open an issue on [GitHub](https://github.com/jliezed/pbi-audit).

---

## License

MIT — see [LICENSE](LICENSE).
