Forum Discussion

omacx00's avatar
omacx00
Frequent Visitor
2 years ago

Automatic retry on failed PBI dataset refresh

I have multiple reports using data from data mart on SQL server. In SQL server I have a job that after updating all data marts calls refresh specific reports in Power BI via API. What I can't do is to somehow set up an automatic retry of the Power BI dataset refresh attempt in case the refresh fails. I've tried it via Power Automate, but I haven't found any usable Power BI trigger there..
Any idea?

2 Replies

  • Hi omacx00,

     

    Since you are already orchestrating your refreshes via a SQL Server Agent Job calling the Power BI REST API, trying to switch to a Power Automate webhook or event trigger can be clunky. Best is to go ahead with your idea of SQL Server Agent

     

    By moving the logic there, you can leverage a programmatic loop that polls the refresh status and automatically fires a retry if a failure is detected.

     

    Instead of just firing the ExecuteRefresh API command and walking away, your SQL Server script (whether it is written in PowerShell or a Python wrapper executed by the agent) needs to handle a 3-step loop:

     

    • POST the refresh command.
    • GET the refresh history status at a set interval (e.g., check every 30 seconds).
    • LOOP if the status comes back as Failed or Unknown, up to a maximum retry counter (e.g., 3 attempts).

    Let me know if you need help with the code part for this!

  • Hi omacx00 

    The cleanest way to handle this without relying on nonexistent Power BI Power Automate triggers is to let your existing SQL Server Agent job control the retry logic directly through the Power BI REST API. Instead of just firing a single asynchronous "fire-and-forget" API call to trigger the refresh, you can modify your SQL job step—using either a PowerShell script task or a Python script—to poll the status of that refresh after triggering it. The script can hit the PostRefresh endpoint to start the process, enter a loop that sleeps for a few minutes, and repeatedly call the GetRefreshHistory API endpoint to check the execution status; if the API returns a status of "Failed," your script can automatically loop back to re-trigger the PostRefresh request up to a maximum number of defined retry attempts. If your company's security policies completely prevent you from running long-polling loops inside your SQL Agent environment, you can shift the orchestration to Azure Logic Apps or a standard Power Automate flow by using a Scheduled Cloud Trigger that runs at a designated time shortly after your SQL data mart job finishes. Inside this automated flow, you use the standard HTTP action to trigger the Power BI refresh, insert a "Until" loop container that continually calls the refresh history endpoint every few minutes until it registers as "Completed" or "Failed," and use a native conditional control branch so that if a "Failed" status is detected, the flow automatically executes another HTTP refresh request, cleanly isolating your retry logic within a managed cloud workflow.