Skip to main content

Find, remove, and copy measures in Power BI PBIP/TMDL projects

Project description

Power BI Measure Tool

A command-line tool for managing measures in Power BI PBIP projects using the TMDL format.

PyPI version Python License: MIT


Features

Mode What it does
Clean Scan for unused measures across your semantic model and optionally delete them
Copy Copy or move measures between projects or tables with automatic structure detection

Copy mode scenarios (auto-detected)

  • Same project → different table — reorganise measures between tables
  • Different project, same table structure — auto-maps identical table names
  • Different project, different tables — guided interactive table mapping

DAX formatting

All measures are cleaned before writing: dedented, trailing whitespace removed, blank lines collapsed. formatString and description metadata are preserved; ephemeral properties like lineageTag are intentionally dropped so the target file gets fresh ones from Power BI.


Requirements

  • Python 3.8+
  • Power BI project saved in PBIP format with TMDL enabled (File → Options → Preview features → Store semantic model in TMDL format)

Installation

pip install powerbi-measure-tool

Or with pipx (recommended for CLI tools — keeps it isolated):

pipx install powerbi-measure-tool

Usage

Clean mode — find and remove unused measures

# Dry run: show which measures are unused (no files changed)
pbi-measure ./MyWorkspace

# Execute: permanently delete unused measures
pbi-measure ./MyWorkspace --execute

# Treat measures that only appear in unapplied filter panes as unused
pbi-measure ./MyWorkspace --execute --ignore-unapplied-filters

Example output:

══════════════════════════════════════════════════════════════
  Power BI Measure Tool  v0.1.0
══════════════════════════════════════════════════════════════
  Source Report : Sales Dashboard.Report
  Source SM     : Sales Dashboard.SemanticModel
  Mode          : 🔍  DRY RUN — no files will be changed
══════════════════════════════════════════════════════════════

📊  Measures found:
    • 24 in SemanticModel (TMDL)
    • 0 report-level
    • 24 total

🔄  Analysing usage...

────────────────────────────────────────────────────
  Status      Table             Measure             Source
────────────────────────────────────────────────────
  ✅ USED     Sales             Total Revenue       semantic_model
  ✅ USED     Sales             Gross Profit        semantic_model
  ...
  ❌ UNUSED   Sales             Old KPI Draft       semantic_model
────────────────────────────────────────────────────

  Total: 24  |  ✅ Used: 23  |  ❌ Unused: 1

💡  Run with --execute to permanently delete the 1 unused measure(s).

Copy mode — copy or move measures between projects / tables

# Interactive selection (prompts you to pick measures from a numbered list)
pbi-measure ./SourceWorkspace --copy --target ./TargetWorkspace

# Cherry-pick specific measures by name
pbi-measure ./SourceWorkspace --copy --target ./TargetWorkspace \
    --measures "Total Revenue" "Gross Profit" "YTD Sales"

# Copy all measures
pbi-measure ./SourceWorkspace --copy --target ./TargetWorkspace --all-measures

# Copy all and execute (--execute required to write files)
pbi-measure ./SourceWorkspace --copy --target ./TargetWorkspace --all-measures --execute

# Overwrite measures that already exist in the target
pbi-measure ./SourceWorkspace --copy --target ./TargetWorkspace \
    --all-measures --overwrite --execute

# Reorganise: move measures to a different table in the same project
pbi-measure ./MyWorkspace --copy --target ./MyWorkspace \
    --measures "Total Revenue" --execute

Interactive selection example:

┌──────────────────────────────────────────────────────────┐
│           Step 1 — Select Measures to Copy               │
└──────────────────────────────────────────────────────────┘

  📋  Sales
    [  1]  Gross Profit  (#,0.00)
    [  2]  Total Revenue  (#,0.00)
    [  3]  YTD Sales  (#,0.00)

  📋  Targets
    [  4]  Revenue Target
    [  5]  Variance to Target

  Syntax: single (3), range (3-7), list (1,3,5-8), or 'all'
  Enter 'q' to quit.

  Your selection: 1,2,4

Path formats accepted

The path and --target arguments accept either:

  • A workspace folder containing both .Report and .SemanticModel subfolders
  • A .Report folder directly
MyWorkspace/                        ← pass this
├── Sales Dashboard.Report/
└── Sales Dashboard.SemanticModel/

How unused measure detection works

The tool performs a multi-pass analysis:

  1. Pass 1 — scans all report JSON files (pages, visuals, bookmarks) for structured Measure references and DAX string expressions
  2. Pass 2+ — marks any measure referenced in the DAX of an already-used measure as used (handles measure-calls-measure chains)
  3. Repeats until no new used measures are found
  4. Anything still unmarked → UNUSED

CHANGELOG

0.1.0

  • Initial release
  • Clean mode: detect and delete unused measures
  • Copy mode: cherry-pick, range, or all measures
  • Auto-detect target structure (same project / same tables / different tables)
  • DAX formatting on write
  • formatString and description metadata preserved on copy
  • --overwrite flag
  • --ignore-unapplied-filters flag

Contributing

Bug reports and pull requests are welcome at GitHub.

  1. Fork the repo
  2. Create a feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -m 'Add my feature'
  4. Push and open a PR

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

powerbi_measure_tool-0.1.3.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powerbi_measure_tool-0.1.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file powerbi_measure_tool-0.1.3.tar.gz.

File metadata

  • Download URL: powerbi_measure_tool-0.1.3.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for powerbi_measure_tool-0.1.3.tar.gz
Algorithm Hash digest
SHA256 71bf835880f25be1fd89cf585e5ef5e41a598aaebab79877c4ff154015c72aa2
MD5 3a17a6b66a9adab56cc7cbf5afe73963
BLAKE2b-256 10556b335987f262ba12324896bf9274095ad942e373fce7c6c452ff0dca7ded

See more details on using hashes here.

File details

Details for the file powerbi_measure_tool-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for powerbi_measure_tool-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 35e8116dc51e70361e6831aef8787d0a5d9543a8ab1358ac3cd74979c5a1879b
MD5 1f2afc9063bb9d4588ce2e1aafd186d2
BLAKE2b-256 e8bce5d83ce796b825e5f07190909cefe75b2379bfbe6a3ea313c2ce90fff2e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page