Add fix_discourage_implicit_measures: disable SummarizeBy on columns#1150
Add fix_discourage_implicit_measures: disable SummarizeBy on columns#1150KornAlexander wants to merge 1 commit intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new semantic model “fixer” function intended to prevent implicit aggregation behavior by setting the TOM model property DiscourageImplicitMeasures for the semantic model backing a given report.
Changes:
- Introduces
fix_discourage_implicit_measures(report, workspace=None, scan_only=False)to scan and (optionally) settom.model.DiscourageImplicitMeasures = True. - Implements read-only vs read/write behavior via
connect_semantic_model(..., readonly=scan_only)and user-facing status messages.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """ | ||
| Checks the DiscourageImplicitMeasures property on the semantic model that | ||
| backs the given report. If the property is False, sets it to True (unless | ||
| running in scan-only mode). | ||
|
|
||
| Disabling implicit measures is generally recommended and is required for | ||
| calculation groups to work correctly. | ||
|
|
There was a problem hiding this comment.
The PR title/description mention disabling SummarizeBy on columns, but this implementation only sets tom.model.DiscourageImplicitMeasures and never updates any column SummarizeBy settings. Either update the PR messaging to match the actual behavior, or extend the fixer to set SummarizeBy="None" on the intended columns (e.g., numeric, non-hidden columns) if that’s the real goal.
| @log | ||
| def fix_discourage_implicit_measures( | ||
| report: str | UUID, | ||
| workspace: Optional[str | UUID] = None, | ||
| scan_only: bool = False, | ||
| ) -> None: |
There was a problem hiding this comment.
fix_discourage_implicit_measures is not exported from sempy_labs.semantic_model (current semantic_model/__init__.py doesn’t import it or include it in __all__). This makes the documented usage labs.semantic_model.fix_discourage_implicit_measures(...) fail. Please add the import and update __all__ accordingly (and ensure the module name is importable after any renames).
| workspace_name, workspace_id = resolve_workspace_name_and_id(workspace) | ||
|
|
||
| dataset_id, dataset_name, dataset_workspace_id, dataset_workspace_name = ( | ||
| resolve_dataset_from_report(report=report, workspace=workspace_id) | ||
| ) |
There was a problem hiding this comment.
workspace_name and dataset_workspace_name are assigned but never used, which will trigger flake8 F841 in this repo’s lint configuration. Either use them in the user-facing messages (helpful to disambiguate same-named datasets across workspaces) or assign to _ to avoid unused locals.
| # Fix / Set DiscourageImplicitMeasures on a Semantic Model | ||
| # Based on: https://github.com/KornAlexander/PBI-Tools/.../2. Check Discourage Implicit Measures.csx |
There was a problem hiding this comment.
The module filename _Fix_DiscourageImplicitMeasures.py uses capital letters, which is inconsistent with the package’s existing snake_case module naming (e.g., _caching.py, _copilot.py, _vertipaq_analyzer.py). Consider renaming to _fix_discourage_implicit_measures.py to keep imports predictable across platforms and match established conventions.
| # Sample usage: | ||
| # fix_discourage_implicit_measures(report="My Report") | ||
| # fix_discourage_implicit_measures(report="My Report", workspace="My Workspace") | ||
| # fix_discourage_implicit_measures(report="My Report", scan_only=True) |
There was a problem hiding this comment.
The inline "Sample usage" block at module bottom is unusual for this package (most modules rely on docstrings/docs). Consider removing it or moving the examples into the function docstring / docs so it doesn’t become stale.
Fix Discourage Implicit Measures
Sets the
DiscourageImplicitMeasuresproperty on a semantic model. When enabled, this prevents Power BI from auto-aggregating columns (e.g., SUM, COUNT) when they are dragged onto visuals, forcing users to use explicit measures instead — a widely recommended best practice.Functions Added
fix_discourage_implicit_measures(report, workspace=None, scan_only=False)Files
src/sempy_labs/semantic_model/_Fix_DiscourageImplicitMeasures.py(new file)src/sempy_labs/semantic_model/__init__.py(updated exports)Usage
PBI Fixer Contribution — Overview
This PR is part of the PBI Fixer contribution to semantic-link-labs — an interactive ipywidgets-based UI for scanning and fixing Power BI reports and semantic models directly in Microsoft Fabric Notebooks.
The PBI Fixer provides a tabbed ipywidgets interface (Semantic Model Explorer, Report Explorer, Perspective Editor, Vertipaq Analyzer) that lets users interactively scan, inspect, and fix Power BI artifacts without leaving the notebook. All underlying fixer functions also work as standalone API calls, so users can integrate them into scripts and pipelines without the UI.
Contribution Structure
The full contribution (~17K lines across 68 files) is split into 22 focused PRs across 6 phases to keep each PR reviewable and self-contained. Only new files are added in Phases 1–4 and 6 — no existing SLL code is modified.
/)..Find()fixes and expression capture (tom/_model.py), Vertipaq analyzer enhancements with memory/column-level analysis (_vertipaq.py, ~1000 lines changed), and various small fixes across_items.py,_item_recovery.py,_helper_functions.py,_export_report.py,_sql.py, andadmin/_tenant.py. These carry higher merge conflict risk and may need closer review or discussion.Dependencies & Review Order
sempy_labs.report.fix_piecharts(...)orsempy_labs.semantic_model.add_calculated_calendar(...).