<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Processing PBI Premium dataset through XMLA query and polling dataset history after in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Processing-PBI-Premium-dataset-through-XMLA-query-and-polling/m-p/2284084#M33885</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scenario where we need to process individual tables of a data model in Power BI Premium.&lt;/P&gt;&lt;P&gt;We figured this is possible by firing a XMLA query using the following powershell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Import-Module SqlServer 

# Executing a DAX-query to retrieve the property we need in a given scenario
$PbicomWorkspaceUri = 'powerbi://api.powerbi.com/v1.0/myorg/&amp;lt;workspace&amp;gt;'
$PbiDatasetName = "&amp;lt;dataset&amp;gt;"
$XmlaQuery = @"
{
  "refresh": {
    "type": "full",
    "objects": [
      {
        "database": "&amp;lt;dataset&amp;gt;",
        "table": "&amp;lt;table&amp;gt;"
      }
    ]
  }
}
"@

$PbiConnectionString = "Data Source=$PbicomWorkspaceUri;Initial Catalog=$PbiDatasetName"
try
{
  Invoke-ASCmd -Query "$XmlaQuery" -Server "$PbicomWorkspaceUri" -ConnectionString $PbiConnectionString

  Write-Host "XMLA query has been processed succesfully"
}
catch 
{ 
  Write-Host $_.Exception.Message`n
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that Premium is processing the table we need a way to poll whether this has succeeded.&lt;/P&gt;&lt;P&gt;My idea was to poll the power bi rest api on the dataset/{datasetid}/refreshes endpoint. We take the last 10 refreshes and filter on refreshType = ViaXmlaEndpoint, next we take the max startTime in order to find the current refresh.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Login-PowerBI

# URL is a relative or absolute URL of the Power BI entity to access. 
$Responses = Invoke-PowerBIRestMethod -Url 'datasets/&amp;lt;datasetid&amp;gt;/refreshes?$top=10' -Method Get | ConvertFrom-Json

# Filter on refreshType = ViaXmlaEndpoint and take response with max startTime
$LastResponseStatus = ($Responses.value | Where-Object { 
  $ResponseItem = $_
  $ResponseItem.refreshType -eq 'ViaXmlaEndpoint'} |
  Sort-Object -Property @{Expression = 'startTime'; Descending = $false} |
  Select-Object -Last 1).status 

Switch ($LastResponseStatus) {
  'Completed' {$body = 'Refresh completed'}
  'Unknown' {$body = 'Refresh in progress'}
  'Failed' {$body = 'Refresh failed'}
  'Disabled' {$body = 'Refresh disabled'}
}

$body&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the problem is that when the dataset history is of type 'ViaXmlaEndpoint', the message will appear&amp;nbsp;&lt;STRONG&gt;after&lt;/STRONG&gt; processing with status 'Completed'. The Power BI REST API documentation states that &lt;STRONG&gt;during&lt;/STRONG&gt; a refresh it should have status 'Unknown'. When doing a manual refresh the history instantly shows status = 'Unknown'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this expected behaviour?&lt;/P&gt;&lt;P&gt;Is there any other way to poll whether processing via XMLA endpoint has succeeded?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Point is that we fire an Azure function for processing a table, and next we fire another Azure function every 30 seconds to poll whether processing has succeeded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bluecar25_0-1642175622811.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/656322i07E8057893E3852D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bluecar25_0-1642175622811.png" alt="Bluecar25_0-1642175622811.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 16:03:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-01-14T16:03:36Z</dc:date>
    <item>
      <title>Processing PBI Premium dataset through XMLA query and polling dataset history after</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Processing-PBI-Premium-dataset-through-XMLA-query-and-polling/m-p/2284084#M33885</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scenario where we need to process individual tables of a data model in Power BI Premium.&lt;/P&gt;&lt;P&gt;We figured this is possible by firing a XMLA query using the following powershell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Import-Module SqlServer 

# Executing a DAX-query to retrieve the property we need in a given scenario
$PbicomWorkspaceUri = 'powerbi://api.powerbi.com/v1.0/myorg/&amp;lt;workspace&amp;gt;'
$PbiDatasetName = "&amp;lt;dataset&amp;gt;"
$XmlaQuery = @"
{
  "refresh": {
    "type": "full",
    "objects": [
      {
        "database": "&amp;lt;dataset&amp;gt;",
        "table": "&amp;lt;table&amp;gt;"
      }
    ]
  }
}
"@

$PbiConnectionString = "Data Source=$PbicomWorkspaceUri;Initial Catalog=$PbiDatasetName"
try
{
  Invoke-ASCmd -Query "$XmlaQuery" -Server "$PbicomWorkspaceUri" -ConnectionString $PbiConnectionString

  Write-Host "XMLA query has been processed succesfully"
}
catch 
{ 
  Write-Host $_.Exception.Message`n
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now that Premium is processing the table we need a way to poll whether this has succeeded.&lt;/P&gt;&lt;P&gt;My idea was to poll the power bi rest api on the dataset/{datasetid}/refreshes endpoint. We take the last 10 refreshes and filter on refreshType = ViaXmlaEndpoint, next we take the max startTime in order to find the current refresh.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Login-PowerBI

# URL is a relative or absolute URL of the Power BI entity to access. 
$Responses = Invoke-PowerBIRestMethod -Url 'datasets/&amp;lt;datasetid&amp;gt;/refreshes?$top=10' -Method Get | ConvertFrom-Json

# Filter on refreshType = ViaXmlaEndpoint and take response with max startTime
$LastResponseStatus = ($Responses.value | Where-Object { 
  $ResponseItem = $_
  $ResponseItem.refreshType -eq 'ViaXmlaEndpoint'} |
  Sort-Object -Property @{Expression = 'startTime'; Descending = $false} |
  Select-Object -Last 1).status 

Switch ($LastResponseStatus) {
  'Completed' {$body = 'Refresh completed'}
  'Unknown' {$body = 'Refresh in progress'}
  'Failed' {$body = 'Refresh failed'}
  'Disabled' {$body = 'Refresh disabled'}
}

$body&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now the problem is that when the dataset history is of type 'ViaXmlaEndpoint', the message will appear&amp;nbsp;&lt;STRONG&gt;after&lt;/STRONG&gt; processing with status 'Completed'. The Power BI REST API documentation states that &lt;STRONG&gt;during&lt;/STRONG&gt; a refresh it should have status 'Unknown'. When doing a manual refresh the history instantly shows status = 'Unknown'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this expected behaviour?&lt;/P&gt;&lt;P&gt;Is there any other way to poll whether processing via XMLA endpoint has succeeded?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Point is that we fire an Azure function for processing a table, and next we fire another Azure function every 30 seconds to poll whether processing has succeeded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bluecar25_0-1642175622811.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/656322i07E8057893E3852D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bluecar25_0-1642175622811.png" alt="Bluecar25_0-1642175622811.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 16:03:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Processing-PBI-Premium-dataset-through-XMLA-query-and-polling/m-p/2284084#M33885</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-01-14T16:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: Processing PBI Premium dataset through XMLA query and polling dataset history after</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Processing-PBI-Premium-dataset-through-XMLA-query-and-polling/m-p/2285044#M33890</link>
      <description>&lt;P&gt;You can run another query to look at the last refresh date for each partition.&amp;nbsp; You would take a snapshot of that date before initiating the refresh, and then check if that date has changed to a more recent date. Would be interesting to see if that date updates when the refresh fails (i would hope not - but then you would also not know &lt;STRONG&gt;when&lt;/STRONG&gt; it failed).&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jan 2022 20:04:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Processing-PBI-Premium-dataset-through-XMLA-query-and-polling/m-p/2285044#M33890</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2022-01-15T20:04:53Z</dc:date>
    </item>
  </channel>
</rss>

