Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/sempy_labs/semantic_model/_Fix_IsAvailableInMdxTrue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Fix "Set IsAvailableInMdx to true on necessary columns" — standalone BPA fixer.

from typing import Optional
from uuid import UUID


Comment thread
KornAlexander marked this conversation as resolved.
def fix_isavailable_in_mdx_true(
dataset: str,
Comment thread
KornAlexander marked this conversation as resolved.
Outdated
workspace: Optional[str | UUID] = None,
scan_only: bool = False,
):
"""
Sets IsAvailableInMDX to True on key/attribute columns that incorrectly have it False.

Targets columns that are: (a) used as keys in relationships (To side), or
(b) used in hierarchies, or (c) marked as IsKey.

Parameters
----------
dataset : str
Name of the semantic model.
workspace : str | uuid.UUID, default=None
The Fabric workspace name or ID.
scan_only : bool, default=False
If True, only reports what would be fixed without making changes.
"""
from sempy_labs.tom import connect_semantic_model

fixed = 0
with connect_semantic_model(dataset=dataset, readonly=scan_only, workspace=workspace) as tom:
# Collect columns that should have IsAvailableInMDX = True
needed = set()
for rel in tom.model.Relationships:
needed.add((str(rel.ToTable.Name), str(rel.ToColumn.Name)))
for table in tom.model.Tables:
for h in table.Hierarchies:
for lvl in h.Levels:
needed.add((str(table.Name), str(lvl.Column.Name)))
for col in table.Columns:
if col.IsKey:
needed.add((str(table.Name), str(col.Name)))

for table in tom.model.Tables:
for col in table.Columns:
if (table.Name, col.Name) in needed and not col.IsAvailableInMDX:
Comment thread
KornAlexander marked this conversation as resolved.
if scan_only:
print(f" Would fix: '{table.Name}'[{col.Name}] IsAvailableInMDX → True")
else:
col.IsAvailableInMDX = True
print(f" Fixed: '{table.Name}'[{col.Name}] IsAvailableInMDX → True")
fixed += 1
if not scan_only and fixed > 0:
tom.model.SaveChanges()

action = "Would fix" if scan_only else "Fixed"
print(f" {action} {fixed} column(s).")
return fixed
3 changes: 3 additions & 0 deletions src/sempy_labs/semantic_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
"make_discoverable",
"enable_query_caching",
]

from ._Fix_IsAvailableInMdxTrue import fix_isavailable_in_mdx_true
__all__ += ["fix_isavailable_in_mdx_true"]
Loading