How to Clone and Rebind Power BI Semantic Models
- Prathy Kamasani
- May 15
- 2 min read
While it may not be considered best practice, I have occasionally needed to clone semantic models during my time working with Power BI for various reasons. There are valid use cases where this approach can be beneficial. For instance, I was using it to duplicate FUAM reports for the Semantic Model Analyser.
In this post, I’ll walk through how to:
Clone a semantic model
Clone a report if in PBIR format or else make a copy
Rebind the cloned report to the new model
Step 1: Clone the Semantic Model
Start by copying the dataset URL from Power BI Service. Then extract the workspace and dataset IDs.
!pip install semantic-link-labs --quiet
import sempy_labs as labs
import re
def extract_dataset_ids(url):
match = re.search(r"groups/([a-f0-9-]+)/datasets/([a-f0-9-]+)", url)
if not match:
raise ValueError("Invalid dataset URL.")
return match.group(1), match.group(2)
try:
dataset_url = "<https://app.powerbi.com/groups/{workspaceId}/datasets/{datasetId}/details>"
source_workspace, source_dataset = extract_dataset_ids(dataset_url)
target_dataset = "Semantic_Model_Meta_Data_Analyzer_SM"
labs.deploy_semantic_model(
source_dataset=source_dataset,
source_workspace=source_workspace,
target_dataset=target_dataset,
target_workspace=source_workspace,
refresh_target_dataset=True,
overwrite=False
)
print("Semantic model cloned successfully.")
except Exception as e:
print(f"Error during semantic model deployment: {e}")
Step 2: Clone the Report
Next, extract the report ID from the report URL and clone it with a new name. This work siwth PBIR only . Otherwise. I would just copy existing report and then rebind it.
def extract_report_ids(url):
match = re.search(r"groups/([a-f0-9-]+)/reports/([a-f0-9-]+)", url)
if not match:
raise ValueError("Invalid report URL.")
return match.group(1), match.group(2)
try:
report_url = "<https://app.powerbi.com/groups/{workspaceId}/reports/{reportId}>"
report_workspace, report_id = extract_report_ids(report_url)
cloned_report_name = "Cloned Report - Dev"
labs.report.clone_report(
report=report_id,
cloned_report=cloned_report_name,
workspace=report_workspace,
target_workspace=report_workspace
)
print("Report cloned successfully.")
except Exception as e:
print(f"Error during report cloning: {e}")
Step 3: Rebind the Cloned Report
Finally, rebind the cloned report to the new semantic model.
try:
labs.report.report_rebind(
report=cloned_report_name,
dataset=target_dataset,
report_workspace=report_workspace,
dataset_workspace=source_workspace
)
print("Report rebound to the new dataset successfully.")
except Exception as e:
print(f"Error during report rebinding: {e}")
And here is the link on Git - https://github.com/prathyusha-kamasani/Blog-Posts/blob/main/clone_and_rebind_powerbi.py
Keep Smiling,
Prathy 😊
Comments