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.
No problem Anonymous .
Thanks for the extra detail!
Yes, I understand that you are ultimately wanting to publish a report with live connection to semantic model to the target workspace.
I'm trying to isolate the cause of the error, which I suspect may relate to the semantic model that the report is live-connected to.
If the downloaded report has a live connection to an existing semantc model in Workspace A, and is then published to Workspace B (using any means), the report will remain live-connected to the semantic model in Workspace A, and will not automatically "rebind" to any semantic model in Workspsace B.
To bind the report to the semantic model in Workspace B, you would need to either need to change the live connection before publishing, or publish first then rebind using Reports - Rebind Report In Group (unfortunately not available via cmdlets as far as I'm aware).
If the account that is publishing the report with New-PowerBIReport does not have suitable permissions to access the semantic model in Workspace A, then New-PowerBIReport will return an error. Uploading/publishing the report manually with the same account would also return an error.
I suggest attempting to manually to upload the report to the target workspace using "Import" within the Workspace, with the same account that is being used for New-PowerBIReport. If you receive an error message, then that would confirm that's the issue.
Hi OwenAuger ,
Thank you for the suggestion. We used two separate accounts per each Power BI workspace and each account had permissions only for its workspace. After creating a separate account that has permissions to both workspaces, it resolved the issue and we can successfully publish reports now.
We also updated our scripts to publish a report first and then rebind it to use a dataset in a target workspace using Reports - Rebind Report In Group. However, after rebinding, it just creates a separate copy of the same report each time we publish a report with the same name even though we use the "ConflictAction CreateOrOverwrite" paramter for the "New-PowerBIReport" cmdlt in our scripts. We need to overwrite the report instead. Is there a way to handle it or maybe there is a way to change the live connection before publishing by using scripts?
- v-hashadapu1 year agoCommunity Support
Hi Anonymous , Thank you for reaching out to the Microsoft Community Forum.
The New-PowerBIReport cmdlet is not the right tool. While it includes a ConflictAction CreateOrOverwrite parameter, it fails when the report is connected to an external dataset. This is because Power BI treats the report as a new object due to the embedded dataset reference, which it doesn't resolve correctly during publish. Instead, you should use the Import-PowerBIReport cmdlet, which reliably supports overwriting reports in a workspace. This method ensures the report is replaced without needing to delete the existing one manually. However, since the .pbix file retains its original dataset binding from the source workspace, it will continue to point to that dataset even after import.
To fix this, you must explicitly rebind the report to the dataset in the target workspace using the REST API. Power BI does not automatically switch the connection, even if the target dataset has the same name or schema. Rebinding ensures the report uses the correct semantic model in the destination workspace and avoids any cross-workspace dependency issues. Make sure you authenticate using Connect-PowerBIServiceAccount or a service principal and obtain a valid $accessToken for the REST API call. After this process, your report will be updated, overwrite the existing version and point to the correct semantic model in the same workspace.
If this helped solve the issue, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details, always happy to help.
Thank you.- Anonymous1 year agoNot applicable
Hello v-hashadapu , thanks for your reply.
I'm getting the following error when trying to use 'Import-PowerBIReport' cmdlt:
The term 'Import-PowerBIReport' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.And I don't find it in the official docummentation: https://learn.microsoft.com/en-us/powershell/module/microsoftpowerbimgmt.reports/?view=powerbi-ps
Can you please advise?
- Anonymous1 year agoNot applicable
Hello v-hashadapu ,
Can you please advise if 'Import-PowerBIReport' cmdlet is still supported and available?
- v-hashadapu1 year agoCommunity Support
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