Skip to content
David Alzamendi Data Enthusiast

Azure Data Factory Refreshing Azure Analysis Services Model

Azure Data Factory Refresh Analysis Services

Are you looking to easily refresh your Azure Analysis Service models and partitions from Azure Data Factory? In this blog post, I show how easy it is to include this feature in Azure Data Factory. 

This tutorial will help you build a pipeline that allows you to asynchronously refresh any Azure Analysis Services model using parameters. Once you finish this tutorial, you’ll have a pipeline that you can use and extend for more specific needs. 

Asynchronous execution vs synchronous execution 

  • Asynchronous execution – when you trigger a refresh of a model, but you don’t know the final status of that refresh. You get the response of the REST API call, but not the final status of the refresh. Most REST APIs work under this method. 
  • Synchronous execution – when you trigger a refresh, the response will not come back until the execution finishes, so you know the status of the execution. 

Can you build workaround in Azure Data Factory? Yes, I will cover this in an upcoming post, but let’s build something reusable first.  

In addition, you need to consider that a synchronous execution means that you need to pay more for your Azure Data Factory pipelines. 

Giving Azure Data Factory access to Azure Analysis Services 

Firstly, you need to give Azure Data Factory access to your Azure Analysis Services model to perform these operations using managed service identities.  

There isn’t an easy way to do this from the Azure portal without getting confused. So, let’s use PowerShell. 

Azure Data Factory has a managed identity created in the backend that you can use to access Analysis Services. 

You need to get your App ID using Azure Active Directory (Option A) or with the PowerShell script provided below (Option B).

If you are trying to refresh from Azure Synapse Analytics, use the Azure Active Directory Method.

Pre-requisite Option A: Get Managed Identity Id from Active Directory

Copy the Tenant ID.

Pre-requisite Option A: Get Managed Identity Id from Active Directory

Find your Azure Data Factory or Synapse Analytics:

Pre-requisite Option A: Get Managed Identity Id from Active Directory
Find your managed identity

Copy your App ID.

Pre-requisite Option A: Get Managed Identity Id from Active Directory
Copy Managed Identity Id

Pre-requisite B: Get Managed Identity Id with script (only Azure Data Factory)

Install-module Az 
Import-Module Az.DataFactory


In some scenarios, you will need to change the policy:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Execute this command in Power Shell and copy the output, download a copy of the script from here.`

# This script returns the Azure Data Factory MSI to give access to your service 

# Install module Azure if it is not available 

# Install-module Az 

# Import-Module Az.DataFactory

# Pre-requisite, connect to your Azure account 

# Connect-AzAccount 

$AzureDataFactoryName = "" 

$ResourceGroupName = "" 

 

$TenantId= (Get-AzDataFactoryV2 -ResourceGroupName "rg-dataanalytics"  -Name "df-techtalkcorner").Identity.TenantId 

$PrincipalId= (Get-AzDataFactoryV2 -ResourceGroupName "rg-dataanalytics"  -Name "df-techtalkcorner").Identity.PrincipalId 

$ApplicationId = Get-AzADServicePrincipal -ObjectId $PrincipalId 

$ApplicationId =($ApplicationId).ApplicationId 

 

# Copy the following user and give it access in Azure Analysis Services 

Write-Host "app:$ApplicationId@$TenantId"  # This scripts returns the Azure Data Factory MSI to give access to your service
Pre-requisite B: Get Managed Identity Id with script (only Azure Data Factory)

Grant Azure Data Factory Access

Then, you need to give Azure Data Factory access to Analysis Services. 

Give Azure Data Factory access to Analysis Services

Go to security and click “add.” 
Make sure you include “app:” at the beginning.

Grant Azure Data Factory Access

Finally, don’t forget to save it. 

Grant Azure Data Factory Access

Creating the reusable pipeline 

Azure Data Factory can refresh Azure Analysis Services tabular models, so let’s create a pipeline. You can download a copy of the pipeline from here.

The solution also works if the model has spaces in the name.

Creating the reusable pipeline

First, create the required parameters to make the pipeline reusable across different models. Don’t forget to define a generic name for your pipeline. 

Creating the reusable pipeline

Drag and drop a Web activity in the pipeline. To refresh the model, I use Azure Analysis Services REST APIs. 

Creating the reusable pipeline

Configure the Web Activity as follows. You want to use the parameters that we have previously created. Copy the strings. 

  1. REST API endpoint 
@concat('https://',pipeline().parameters.Region,'.asazure.windows.net/servers/',pipeline().parameters.ServerName,'/models/',pipeline().parameters.ModelName,'/refreshes') 
  1. HTTP Body 
@concat( 

'{ 

    "Type": "',pipeline().parameters.RefreshType,'", 

    "CommitMode": "transactional", 

    "MaxParallelism":10, 

    "RetryCount": 2, 

    }' 

) 
  1. https://*.asazure.windows.net  
Creating the reusable pipeline

You can see in the picture above that we are using managed identities (MSI) to access Azure Analysis Services Rest API.  

Now let’s test it. Include the correct values for the parameters. 

Creating the reusable pipeline

The output should tell you if it was able to connect and trigger the refresh. Remember, this is an asynchronous execution so you won’t know the status of the refresh execution. 

Creating the reusable pipeline

Summary 

You have created a reusable Azure Data Factory pipeline that you can use to refresh Azure Analysis Services models asynchronously. It’s easy to extend it with new futures.  

What’s Next? 

In upcoming blog posts, we’ll continue to explore Azure Data Services features.  

Please  follow Tech Talk Corner on Twitter for blog updates, virtual presentations, and more!         

Check out these other posts

All 35 guides
Azure Data Factory

How to Extract Power BI Objects

To extract Power BI Objects with Azure Data Factory or Synapse Analytics - workspaces, reports, datasets deployed to Power BI tenant - create or download the solution here.

6 min read

13 comments

  1. zahid hossain

    Where should I execute the ps1 script? In my desktop?

    Reply

    1. Hi Zahid,

      Yes, you can execute it in your desktop, it just creates the MSI that you need in Azure Active Directory.

      Regards,
      David

      Reply

  2. Tirta

    Hi David, can we also connect from Synapse Data Factory?

    Reply

    1. Hi Tirta,

      This will work with Synapse Analytics, get the application Id from Azure Active Directory as the script is only for Azure Data Factory.

      Synapse and Analysis Services

      Regards,

      David

      Reply

  3. Colin

    how do we pass in a model name in the data factory parameter where the model name contains a space?

    Reply

    1. Hi Colin,

      I have just tested the solution with spaces in the model name and it seems to work as well.

      Spaces in name

      Spaces in name results

      Let me know if you still have problems.

      Regards,

      David

      Reply

  4. Ravi Shukla

    Hello Team ,

    I am using REST API method for processing the data on azure analysis cube that is working fine .

    I need to create new partition for each month and process only particular month partition month only .

    i.e. we are running on AUG 2021 hence we need to create the partition as TableName_Aug2021 and query will come as “select * from table name where date between ‘1-aug-2021’ and ’31-aug2021′”.

    once this partition gets created we need to process only this TableName_Aug2021 this partition using REST API method .

    Please let me know if you need any information .

    Reply

    1. Mitch

      I would create an azure function that uses the TOM to create the partitions, then pass the current partition name you want processed to this solution.

      Reply

  5. Govardhan

    Hello David – I followed the instructions and used Service Principal instead of MSI for Authentication. When I run the pipeline manually, it refreshed the AAS database with the new data. However, sometimes I do see that the same ADF pipeline ran successfully, but the data is not refreshed as indicated by the LastRefreshDate for the AAS database in SSMS. I do not know why this is happening. Is it because the OAuth2 token expires every 1 hour? Please advise.
    Thanks

    Reply

  6. Did you publish the workaround for synchronous execution yet?

    Reply

  7. RJust

    Hello – this was very helpful for a beginner like myself in the world of Azure. I was able to get this working to refresh a single AAS but is it possible to refresh all models in a server or refresh specific models without creating a new pipeline for each one?

    Reply

  8. Singgih

    I have tried this but results in error Unauthorized.

    Did I miss something?

    Reply

Leave a comment

Your email address isn't published.

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.