cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nikywilliams
Frequent Visitor

"A task was cancelled" exception sometimes thrown when executing "Export-PowerBIReport" cmdlet

Sometimes I’ll see an exception thrown that tells me “A task was cancelled” when executing "Export-PowerBIReport" cmdlet. I did come across a post that indicated the tenant may be overburdened when this exception is thrown. Anyone have any thoughts?

PS C:\Windows\system32> Export-PowerBIReport -Id 4ced13d4-xxxx-xxxx-xxxx-xxxxxxxxxxxx -OutFile 'c:\tmp\test.pbix' -Verbose
Export-PowerBIReport : A task was canceled.
At line:1 char:1
+ Export-PowerBIReport -Id 4ced13d4-xxxx-xxxx-xxxx-xxxxxxxxxxxx -OutFil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Power...rtPowerBIReport:ExportPowerBIReport) [Export-PowerBIReport], TaskCanceledException
    + FullyQualifiedErrorId : A task was canceled.,Microsoft.PowerBI.Commands.Reports.ExportPowerBIReport

PS C:\Windows\system32> Resolve-PowerBIError -Last


   HistoryId: 11


Message        : A task was canceled.
StackTrace     :    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.PowerBI.Api.V2.Reports.d__9.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.PowerBI.Api.V2.ReportsExtensions.d__35.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.PowerBI.Api.V2.ReportsExtensions.ExportReport(IReports operations, String reportKey)
                    at Microsoft.PowerBI.Common.Api.Reports.ReportsClient.ExportReport(Guid reportId, Nullable`1 workspaceId)
                    at Microsoft.PowerBI.Commands.Reports.ExportPowerBIReport.ExecuteCmdlet()
                    at Microsoft.PowerBI.Commands.Common.PowerBICmdlet.ProcessRecord()
Exception      : System.Threading.Tasks.TaskCanceledException
InvocationInfo : {Export-PowerBIReport}
Line           : Export-PowerBIReport -Id 4ced13d4-xxxx-xxxx-xxxx-xxxxxxxxxxxx -OutFile 'c:\tmp\test.pbix' -Verbose
Position       : At line:1 char:1
                 + Export-PowerBIReport -Id 4ced13d4-xxxx-xxxx-xxxx-xxxxxxxxxxxx -OutFil ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 11

 

3 REPLIES 3
Icey
Community Support
Community Support

Hi @nikywilliams ,

 

This issue doesn't happen every time, but only occasionally, does it?

 

If so, it may casued by tenant/capacity running too hot. And this process got kicked out because other processes needed the memory/renderers. Try again when resources are sufficient.

Reference: Get-PowerBIReport - intermittent task canceled errors

 

Or try to assign a long enough timoutSec parameter to specifie how long the request can be pending before it times out.

Reference: Invoke-PowerBIRestMethod # Parameter

 

In addition, you can also try to run your script from a VM within Azure because Azure-Azure throughputs are a lot faster.

Reference: Importing large PBI reports to group workspace with New-PowerBIReport error: 'A task was canceled.'

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@IceyUnfortunately, calling "Invoke-PowerBIRestMethod" directly (rather than using "Export-PowerBIReport") did not work either, I received an internal 500 error (shown below). I have used "Invoke-PowerBIRestMethod" in the past for other needs. I ended up just rolling my own automated process that navigated the PBI Service and clicked the "download PBIX" button for me for all the datasets...it's janky but it seems to work for this immedate need I have. Hopefully (very very soon) Microsoft will create better ways of parsing metadata in the future.

 

Message        : Response status code does not indicate success: 500 (Internal Server Error).
StackTrace     :    at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
                    at Microsoft.PowerBI.Commands.Profile.InvokePowerBIRestMethod.d__35.MoveNext()
Exception      : System.Net.Http.HttpRequestException
InvocationInfo : {Invoke-PowerBIRestMethod}
Line           : Invoke-PowerBIRestMethod -Url
                 /groups/be92f1f1-xxxx-xxxx-xxxx-xxxxxxxxxxxx/reports/45f363d4-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Export
                 -Method GET -OutFile "D:\test.pbix" -TimeoutSec 900 -Verbose
Position       : At line:1 char:1
                 + Invoke-PowerBIRestMethod -Url /groups/be92f1f1-xxxx-xxxx-xxxx-xxxxxxx ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 3

 

The timoutSec param looks very promising. I completely missed this one, thank you for your input. I'll give this a go and see if it helps. If so, I'll mark this as the accepted solution.

Helpful resources

Announcements
Exciting changes

Power BI Community Changes

Check out the changes to the Power BI Community announced at Build.

May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Kudo Data Story carousel

Data Stories Gallery

Visit our Data Stories Gallery and give kudos to your favorite Data Stories.

Top Solution Authors