Forum Discussion
PowerBIModelNotFoundException when publishing Power BI report to Azure Power BI
- 1 year ago
Hi Anonymous , Thank you for reaching out to the Microsoft Community Forum.
Yes, Power BI Deployment Pipelines can automatically rebind reports to the correct semantic models during deployments between Dev, Test and Prod, if the reports and datasets are included in the pipeline. You just need to configure dataset rules in the pipeline settings to map each report to the appropriate dataset in each stage. When those rules are in place, deploying from one stage to another will automatically rebind the report, no manual steps required. To fully automate this in your Azure DevOps pipeline, you can use the Power BI REST API to trigger deployments between pipeline stages.
Parameterizing live semantic model connections in PBIX files is not supported. When you connect a report to a Power BI dataset, that connection is hardcoded in the PBIX. You can't change it using parameters, environment variables or PowerShell before publishing. The only way to switch the dataset is after publishing, using the Rebind Report In Group API, which you're already doing correctly.
If this helped solve the issue, please consider marking it “Accept as Solution” and giving a ‘Kudos’ so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.
Hi Anonymous , Thank you for reaching out to the Microsoft Community Forum.
We are sorry for the earlier answer. Can you please try the below and share your thoughts.
# Required variables (set via pipeline or environment)
$workspaceId = "YOUR_WORKSPACE_ID"
$reportName = "YOUR_REPORT_NAME"
$pbixFilePath = "PATH_TO_YOUR_PBIX"
$datasetName = "YOUR_DATASET_NAME"
$clientId = "YOUR_CLIENT_ID"
$clientSecret = "YOUR_CLIENT_SECRET"
$tenantId = "YOUR_TENANT_ID"
# Authenticate
$secureSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($clientId, $secureSecret)
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $tenantId
# Get dataset ID by name
$dataset = Get-PowerBIDataset -WorkspaceId $workspaceId | Where-Object { $_.Name -eq $datasetName }
if (-not $dataset) {
throw "Dataset '$datasetName' not found in workspace '$workspaceId'"
}
$targetDatasetId = $dataset.Id
# Check for existing report
$existingReport = Get-PowerBIReport -WorkspaceId $workspaceId | Where-Object { $_.Name -eq $reportName }
$needsRebind = $true
if ($existingReport) {
# Compare dataset IDs
$currentDatasetId = $existingReport.DatasetId
if ($currentDatasetId -eq $targetDatasetId) {
Write-Host "Report is already bound to correct dataset. Skipping deletion and rebinding."
$needsRebind = $false
} else {
Write-Host "Deleting report due to dataset mismatch."
Remove-PowerBIReport -WorkspaceId $workspaceId -Id $existingReport.Id
}
}
# Publish report
$newReport = New-PowerBIReport -Path $pbixFilePath -Name $reportName -WorkspaceId $workspaceId -ConflictAction CreateOrOverwrite
# Rebind only if needed
if ($needsRebind) {
$accessToken = (Get-PowerBIAccessToken).Authorization
$rebindUri = "https://api.powerbi.com/v1.0/myorg/groups/$workspaceId/reports/$($newReport.Id)/Rebind"
$rebindBody = @{ datasetId = $targetDatasetId } | ConvertTo-Json
$rebindHeaders = @{
"Authorization" = $accessToken
"Content-Type" = "application/json"
}
Invoke-RestMethod -Method Post -Uri $rebindUri -Headers $rebindHeaders -Body $rebindBody
Write-Host "Report successfully rebound to dataset '$datasetName'."
}
Disconnect-PowerBIServiceAccount
Hi v-hashadapu ,
Thank you for sharinhg this workaround. We will try it out.
Besides this method, we are also looking into the other options:
- Using Power BI Deployment Pipelines. Let's say we have three workspaces: Dev, Test, and Production, and we publish PBIX reports using PowerShell scripts to Dev workspace. With Power BI Deployment pipelines, would it be possible to configure these pipelines to automatically rebind reports to use the appropriate semantic models in Test and Production workspaces when deploying and synchronizing changes from Dev to Test and from Test to Production stages?
- Creating parameters that function as environment variables such as Dev, Test, and Production in PBIX reports. We can probably try setting these environment variables to parametrize connections to semantic models. Would it be possible to update these environment variables in PBIX reports by using PowerShell scripts with the appropriate semantic models before publishing the reports to target workspaces?
- Anonymous1 year agoNot applicable
- v-hashadapu1 year agoCommunity Support
Hi Anonymous , Thank you for reaching out to the Microsoft Community Forum.
Yes, Power BI Deployment Pipelines can automatically rebind reports to the correct semantic models during deployments between Dev, Test and Prod, if the reports and datasets are included in the pipeline. You just need to configure dataset rules in the pipeline settings to map each report to the appropriate dataset in each stage. When those rules are in place, deploying from one stage to another will automatically rebind the report, no manual steps required. To fully automate this in your Azure DevOps pipeline, you can use the Power BI REST API to trigger deployments between pipeline stages.
Parameterizing live semantic model connections in PBIX files is not supported. When you connect a report to a Power BI dataset, that connection is hardcoded in the PBIX. You can't change it using parameters, environment variables or PowerShell before publishing. The only way to switch the dataset is after publishing, using the Rebind Report In Group API, which you're already doing correctly.
If this helped solve the issue, please consider marking it “Accept as Solution” and giving a ‘Kudos’ so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.