Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi everyone,
I exported a report+dataset from PowerBI Desktop and after unzipping the pbix file I would like to amend the connections json in order to change the dataset against the report. There are three fields which need to be changed:
Catalog: Which is the datasetID
PbiModelDatabaseName: Which is the datasetID again.
PbiServiceModelId: which is 7digits(in my case), but have no idea how can I get this digit through the API.
It is crucial to get this through a "programable" way (so through api).
I saw few post about this but haven't found the answer.
Someone managed to do this somehow? It would be very very very useful 🙂
Thank you.
I have the same issue.
Anyone has a solution here?
Anyone knows what the PbiServiceModelId exactly is?
What i found out:
If you change the datasetID and open the pbix file again it is reestablishing the connection to the PBIService and after saving the PbiServiceModelId is changed.
But I do not know how to get the id via API.
Currently there is no straight forward approach to retrieve PbiServiceModelId(numeric digit) using API.
There are multiple workarounds you could try to do the automation. I have followed below mentioned approach.
1. Deploy Model.pbix to pbi service.
2. Login to powerbi.com to grab the PbiServiceModelId. After logging in navigate to any workspaces, it makes a call to SharedDatasets to fetch all datasets. You could grab the right one.
3. You can use below ZipUnZip function to update the connection.
function Set-DatasetId([string] $directoryPath, [string] $reportName)
{
$zipFileName = "$($directoryPath)\$($reportName).zip"
$pbiFileName = "$($directoryPath)\$($reportName).pbix"
Copy-Item $pbiFileName $zipFileName -Force
$unZippedirname = "$($directoryPath)\$($reportName)"
Expand-Archive -Path $zipFileName -DestinationPath $unZippedirname -Force -Verbose
Write-Host "$($directoryPath)\$($reportName)"
$securityBindingsFileName = "$($unZippedirname)\SecurityBindings"
Remove-Item -Path $securityBindingsFileName -Force -ErrorAction SilentlyContinue
$connectionFileName = "$($unZippedirname)\Connections"
$fileContent = (Get-Content -Raw $connectionFileName) -replace $global:orgdatasetId, $global:PPACModelDatasetId
$fileContent = $fileContent -replace $global:orgModelId , $PpacModelId
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($connectionFileName, $fileContent, $Utf8NoBomEncoding)
$contentTypesFileName = "$($unZippedirname)"
Get-ChildItem "$contentTypesFileName" -Filter *.xml | Sort-Object -desc |
Foreach-Object {
$contentTypeorg= $_.Name
$filenameExracted= $_.Name.Replace("[","``[").Replace("]","``]")
if ($filenameExracted -eq "``[Content_Types``].xml")
{
$filenameExracted= $contentTypesFileName+'\'+ $filenameExracted
$fileContent = (Get-Content -Raw $filenameExracted) -replace '<Override PartName="/SecurityBindings" ContentType="" />', ''
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
#[System.IO.File]::WriteAllLines($_.FullName, $fileContent, $Utf8NoBomEncoding)
}
}
$ZipDirName = "$($unZippedirname)\*"
Compress-Archive -Path $ZipDirName -DestinationPath $zipFileName -Update -Verbose
Remove-Item -Path $pbiFileName -Force -ErrorAction SilentlyContinue -Verbose
Copy-Item $zipFileName $pbiFileName -Force -Verbose
Write-Host "PowerBI file $($reportName) are updated with dataset"
}
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
2 | |
2 | |
1 | |
1 |