Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I have a single page report designed in power bi. It is designed to show information for one project at a time. We have a total of 100 projects. Instead of clicking in power bi, pick a project and then export to pdf, is there anyway to “export to pdf” all projects at the same time? Thank you for your time.
Solved! Go to Solution.
Hi @Kayvon ,
Please try to use PowerShell script to call Reports - Export To File In Group , Reports - Get Export To File Status In Group and Get File Of Export To File In Group APIs to export multiple reports to PDF at one time. The report needs to be located in Premium or Embedded capacity, and PPU capacity is not supported. For more restrictions, please refer to Considerations and limitations .
Below is my sample PowerShell script to set 3 different parameter values for the report and then export 3 PDF files and save them locally.
# Parameters - fill these in before running the script!
$authUrl = 'https://login.microsoftonline.com/416e-----tenant id-----f54/oauth2/token';
$clientId="98------------20"
$clientSecret = "37G7Q--------------fk"
#This is the location where the file is finally exported to. You can change this location.
$Folder="C:\Users\Administrator\Desktop\"
# Get token
$body = @{
'grant_type' = 'client_credentials';
'resource' = 'https://analysis.windows.net/powerbi/api';
'client_id' = $clientId;
'client_secret' = $clientSecret;
};
$authResponse = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
# Parameters - fill these in before running the script!
$pbireportId = "--------"
$groupID = "------------"
$restURL = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/ExportTo"
# Building Rest API header with authorization token
$headers = @{
"Content-Type" = "application/json";
"Authorization" = $authResponse.token_type + " " + $authResponse.access_token
}
# Export File 1 - set the file format as pdf
$body = "{`"format`":`"pdf`",
`"powerBIReportConfiguration`": { `"reportLevelFilters`": [{ `"filter`": `"DimDate/CalendarYear eq 2012`" }]}
}"
$body
$output= Invoke-RestMethod -Uri $restURL -headers $headers -Method POST -Body $body
# Get File 1 Status
$fileid=$output.id
$restURL01 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid"
$filestatus = "";
Do
{
Write-Output "Waiting for the Export to be available"
$filestatus=Invoke-RestMethod -Uri $restURL01 -headers $headers -Method GET
$filestatus=$filestatus.status
$filestatus
Start-Sleep -Seconds 20
}
While($filestatus -ne "Succeeded")
start-sleep -Seconds 20
# Download the file 1
$restURL03 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid/file"
Invoke-RestMethod -Uri $restURL03 -headers $headers -Method GET -OutFile $Folder"file1.pdf"
# ==============================
# Export File 2 - set the file format as pdf
$body = "{`"format`":`"pdf`",
`"powerBIReportConfiguration`": { `"reportLevelFilters`": [{ `"filter`": `"DimDate/CalendarYear eq 2005`" }]}
}"
$body
$output= Invoke-RestMethod -Uri $restURL -headers $headers -Method POST -Body $body
# Get File 2 Status
$fileid=$output.id
$restURL01 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid"
$filestatus = "";
Do
{
Write-Output "Waiting for the Export to be available"
$filestatus=Invoke-RestMethod -Uri $restURL01 -headers $headers -Method GET
$filestatus=$filestatus.status
$filestatus
Start-Sleep -Seconds 20
}
While($filestatus -ne "Succeeded")
start-sleep -Seconds 20
# Download the file 2
$restURL03 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid/file"
Invoke-RestMethod -Uri $restURL03 -headers $headers -Method GET -OutFile $Folder"file2.pdf"
# ==============================
# Export File 3 - set the file format as pdf
$body = "{`"format`":`"pdf`",
`"powerBIReportConfiguration`": { `"reportLevelFilters`": [{ `"filter`": `"DimDate/CalendarYear eq 2010`" }]}
}"
$body
$output= Invoke-RestMethod -Uri $restURL -headers $headers -Method POST -Body $body
# Get File 3 Status
$fileid=$output.id
$restURL01 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid"
$filestatus = "";
Do
{
Write-Output "Waiting for the Export to be available"
$filestatus=Invoke-RestMethod -Uri $restURL01 -headers $headers -Method GET
$filestatus=$filestatus.status
$filestatus
Start-Sleep -Seconds 20
}
While($filestatus -ne "Succeeded")
start-sleep -Seconds 20
# Download the file 3
$restURL03 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid/file"
Invoke-RestMethod -Uri $restURL03 -headers $headers -Method GET -OutFile $Folder"file3.pdf"
Referencing: PowerShell Scripts to Export Power BI Reports to PBIX/PDF/PPT
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I'm using similar techiniqe on Powershell calling REST API to export the pdf file from PBI report, its all works fine except the ExporttoFilter at the reportlevel doesn't work. I am trying to enfore filter on the department to export only "Tech" but the exported pdf including all departments. I'm not sure where I've gone wrong ??
@v-kkf-msft @Anand24 @analitica_its @Kayvon
I have already looked into paginated reports, however, based on my understanding, a paginated report is a single report which is longer than one page and does not fit on one screen or one page. It is not multiple reports. Please let me know if you think otherwise. Thank you for your suggestion.
Hi @Kayvon ,
Please try to use PowerShell script to call Reports - Export To File In Group , Reports - Get Export To File Status In Group and Get File Of Export To File In Group APIs to export multiple reports to PDF at one time. The report needs to be located in Premium or Embedded capacity, and PPU capacity is not supported. For more restrictions, please refer to Considerations and limitations .
Below is my sample PowerShell script to set 3 different parameter values for the report and then export 3 PDF files and save them locally.
# Parameters - fill these in before running the script!
$authUrl = 'https://login.microsoftonline.com/416e-----tenant id-----f54/oauth2/token';
$clientId="98------------20"
$clientSecret = "37G7Q--------------fk"
#This is the location where the file is finally exported to. You can change this location.
$Folder="C:\Users\Administrator\Desktop\"
# Get token
$body = @{
'grant_type' = 'client_credentials';
'resource' = 'https://analysis.windows.net/powerbi/api';
'client_id' = $clientId;
'client_secret' = $clientSecret;
};
$authResponse = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
# Parameters - fill these in before running the script!
$pbireportId = "--------"
$groupID = "------------"
$restURL = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/ExportTo"
# Building Rest API header with authorization token
$headers = @{
"Content-Type" = "application/json";
"Authorization" = $authResponse.token_type + " " + $authResponse.access_token
}
# Export File 1 - set the file format as pdf
$body = "{`"format`":`"pdf`",
`"powerBIReportConfiguration`": { `"reportLevelFilters`": [{ `"filter`": `"DimDate/CalendarYear eq 2012`" }]}
}"
$body
$output= Invoke-RestMethod -Uri $restURL -headers $headers -Method POST -Body $body
# Get File 1 Status
$fileid=$output.id
$restURL01 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid"
$filestatus = "";
Do
{
Write-Output "Waiting for the Export to be available"
$filestatus=Invoke-RestMethod -Uri $restURL01 -headers $headers -Method GET
$filestatus=$filestatus.status
$filestatus
Start-Sleep -Seconds 20
}
While($filestatus -ne "Succeeded")
start-sleep -Seconds 20
# Download the file 1
$restURL03 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid/file"
Invoke-RestMethod -Uri $restURL03 -headers $headers -Method GET -OutFile $Folder"file1.pdf"
# ==============================
# Export File 2 - set the file format as pdf
$body = "{`"format`":`"pdf`",
`"powerBIReportConfiguration`": { `"reportLevelFilters`": [{ `"filter`": `"DimDate/CalendarYear eq 2005`" }]}
}"
$body
$output= Invoke-RestMethod -Uri $restURL -headers $headers -Method POST -Body $body
# Get File 2 Status
$fileid=$output.id
$restURL01 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid"
$filestatus = "";
Do
{
Write-Output "Waiting for the Export to be available"
$filestatus=Invoke-RestMethod -Uri $restURL01 -headers $headers -Method GET
$filestatus=$filestatus.status
$filestatus
Start-Sleep -Seconds 20
}
While($filestatus -ne "Succeeded")
start-sleep -Seconds 20
# Download the file 2
$restURL03 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid/file"
Invoke-RestMethod -Uri $restURL03 -headers $headers -Method GET -OutFile $Folder"file2.pdf"
# ==============================
# Export File 3 - set the file format as pdf
$body = "{`"format`":`"pdf`",
`"powerBIReportConfiguration`": { `"reportLevelFilters`": [{ `"filter`": `"DimDate/CalendarYear eq 2010`" }]}
}"
$body
$output= Invoke-RestMethod -Uri $restURL -headers $headers -Method POST -Body $body
# Get File 3 Status
$fileid=$output.id
$restURL01 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid"
$filestatus = "";
Do
{
Write-Output "Waiting for the Export to be available"
$filestatus=Invoke-RestMethod -Uri $restURL01 -headers $headers -Method GET
$filestatus=$filestatus.status
$filestatus
Start-Sleep -Seconds 20
}
While($filestatus -ne "Succeeded")
start-sleep -Seconds 20
# Download the file 3
$restURL03 = "https://api.powerbi.com/v1.0/myorg/groups/$groupID/reports/$pbireportId/Exports/$fileid/file"
Invoke-RestMethod -Uri $restURL03 -headers $headers -Method GET -OutFile $Folder"file3.pdf"
Referencing: PowerShell Scripts to Export Power BI Reports to PBIX/PDF/PPT
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, do you know how much time does it takes to get the response from the loop? thanks in advance
i do not unfortunately. i was unable to follow the above address given resource challenges. thank you.
Bless you Winniz. i will follow your instructions and let you know my findings. i am not an expert so it may take some effort to get it all right. Have a great weekend and thank you for taking the time to respond.