Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Kayvon
Frequent Visitor

export to pdf

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.

1 ACCEPTED 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"

vkkfmsft_0-1643863932016.png

 

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.

 

View solution in original post

7 REPLIES 7
EricShahi
Helper IV
Helper IV

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 ?? 

EricShahi_0-1665686674412.png

@v-kkf-msft @Anand24 @analitica_its @Kayvon 

 

Anand24
Super User
Super User

Hi @Kayvon ,
You might want to search about paginated reports created using Power BI Report Builder. This should solve your issue.

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

 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"

vkkfmsft_0-1643863932016.png

 

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. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors