Skip to content

Add fix_discourage_implicit_measures: disable SummarizeBy on columns#1150

Open
KornAlexander wants to merge 1 commit intomicrosoft:mainfrom
KornAlexander:feature/fix-discourage-implicit-measures
Open

Add fix_discourage_implicit_measures: disable SummarizeBy on columns#1150
KornAlexander wants to merge 1 commit intomicrosoft:mainfrom
KornAlexander:feature/fix-discourage-implicit-measures

Conversation

@KornAlexander
Copy link
Copy Markdown

Fix Discourage Implicit Measures

Sets the DiscourageImplicitMeasures property 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

Function Description
fix_discourage_implicit_measures(report, workspace=None, scan_only=False) Checks and sets the DiscourageImplicitMeasures property on the semantic model that backs the given report.

Files

  • src/sempy_labs/semantic_model/_Fix_DiscourageImplicitMeasures.py (new file)
  • src/sempy_labs/semantic_model/__init__.py (updated exports)

Usage

import sempy_labs as labs

# Check current setting
labs.semantic_model.fix_discourage_implicit_measures("My Report", scan_only=True)

# Enable DiscourageImplicitMeasures
labs.semantic_model.fix_discourage_implicit_measures("My Report")

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.

Phase Focus PRs Description
1 Report Fixers 7 Standalone functions that programmatically fix common Power BI report issues: replace pie charts with bar charts, standardize page sizes to Full HD, apply chart formatting best practices, migrate slicers to slicerbars, hide visual-level filters, clean up unused custom visuals, align visuals, migrate report-level measures, and upgrade reports to PBIR format. Each function operates on PBIR-format report definitions.
2 Semantic Model Fixers 4 Functions that fix and enhance semantic models via XMLA/TOM: add calculated calendar and measure tables, add calculation groups for units and time intelligence, discourage implicit measures, and 19 BPA auto-fixers covering formatting conventions, naming standards, data types, column visibility, sort order, and DAX patterns (e.g., use DIVIDE instead of /).
3 SM Setup & Analysis 3 Setup utilities: configure cache warming queries, set up incremental refresh policies, and prepare semantic models for AI/Copilot integration (descriptions, metadata enrichment).
4 Report Utilities 3 Report-level utilities: auto-generate report page prototypes from a semantic model's structure, extract and apply report themes, and generate IBCS-compliant variance charts.
5 Upstream Enhancements 3 ⚠️ These PRs modify existing SLL code (unlike Phases 1–4 which only add new files). Changes include TOM model .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, and admin/_tenant.py. These carry higher merge conflict risk and may need closer review or discussion.
6 PBI Fixer UI 2 The interactive UI layer: shared UI components (theme, icons, tree builders, layout helpers), BPA scan runners, report helpers, and the main PBI Fixer application with its tabbed interface (SM Explorer, Report Explorer, Perspective Editor, Vertipaq Analyzer). Depends on Phases 1–5 but uses lazy imports to degrade gracefully if individual fixers aren't yet merged.

Dependencies & Review Order

  • Phases 1–4 are fully independent — they only add new files and can be reviewed/merged in any order.
  • Phase 5 is also independent but modifies existing code, so it may benefit from early discussion.
  • Phase 6 (the UI) ties everything together. It depends on the earlier phases but works standalone via lazy imports.
  • All fixer functions work without the UI — they can be called directly as sempy_labs.report.fix_piecharts(...) or sempy_labs.semantic_model.add_calculated_calendar(...).

Copilot AI review requested due to automatic review settings April 9, 2026 16:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) set tom.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.

Comment on lines +21 to +28
"""
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.

Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +15 to +20
@log
def fix_discourage_implicit_measures(
report: str | UUID,
workspace: Optional[str | UUID] = None,
scan_only: bool = False,
) -> None:
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +49
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)
)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +2
# Fix / Set DiscourageImplicitMeasures on a Semantic Model
# Based on: https://github.com/KornAlexander/PBI-Tools/.../2. Check Discourage Implicit Measures.csx
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +87
# 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)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants