Skip to content

Commit

Permalink
XMLA Endpoint workaround: Added script to handle inc refresh hydration (
Browse files Browse the repository at this point in the history
#90)

* Added script to handle inc refresh hydration


---------

Co-authored-by: Daniel Otykier <[email protected]>
  • Loading branch information
mlonsk and otykier authored Apr 4, 2024
1 parent 9092d57 commit cea68c5
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions te3/powerbi-xmla-pbix-workaround.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ However, with the Power BI Project file, it's possible to create a .pbix file fr
![XLMA to PBIX Overview](~/images/power-bi/create-pbix-from-xmla-overview.png)

> [!NOTE]
> The described workaround isn't officially supported by Microsoft. There's no guarantee that it works for every model. Specifically, if you've added custom partitions or other objects [listed here](https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-external-tools#data-modeling-operations), Power BI Desktop may not be able to correctly open the file following this approach.
> The described workaround isn't officially supported by Microsoft. There's no guarantee that it works for every model. Specifically, if you've added custom partitions or other objects [listed here](https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-external-tools#data-modeling-operations), Power BI Desktop may not be able to correctly open the file following this approach. See below for a script to handle incremental refresh partitions.
## Step 1: Create and save an empty Power BI projects (.pbip) file

Expand All @@ -34,7 +34,7 @@ This creates a folder structure that contains an empty _model_ file. This _model

Close Power BI desktop, and proceed with the next step in Tabular Editor.

## Step 2: Open XMLA model with Tabular Editor and save the model as .pbip
## Step 2: Open XMLA model with Tabular Editor

With Tabular Editor open, connect to the Fabric workspace via the XMLA endpoint. Load the Power BI semantic model you want to convert to a .pbix.

Expand All @@ -44,6 +44,9 @@ In Tabular Editor using _File > Save as..._, navigate to the Power BI Project fo

This will save the remote model into the Power BI Project that will now contain the model metadata.

## Step 3.1: Remove incremental refresh partitions and create new (Optional)
Use the Convert Incremental Refresh script below to delete incremental refresh partitions and create a single partition for each table containing the expression used in the incremental refresh expression.


## Step 4: Save to .pbix and open this file in Power BI Desktop

Expand All @@ -55,3 +58,34 @@ Save it to a .pbix using _File > Save As..._ in Power BI Desktop.

## Re-hydrate .pbix
The .pbix now contains the model that was published to the Fabric workspace. When you open the .pbix, you can _re-hydrate_ the file, meaning that you load the data based on the connections specified in the model.

## Convert Incremental Refresh partitions
The above step 4 will fail if the semantic model has incremental refresh enabled as a Power BI desktop model cannot contain multiple partitions.
In this case the following script should be run against the model to convert incremental refresh partitions into single partitions


```csharp
foreach (var t in Model.Tables)
{
if(t.EnableRefreshPolicy)
{
//We will collect the SourceExpression from the Incremental Refresh Source Expression of the table
string m_expression = t.SourceExpression.ToString();

//We will generate a new partition name
string partition_name = t.Name + "-" + Guid.NewGuid();

//Now we will create a new partition
var partition = t.AddMPartition(partition_name, m_expression);
partition.Mode = ModeType.Import;

//Next we will delete all the incremental refresh partitions of the table
foreach (var p in t.Partitions.OfType<PolicyRangePartition>().ToList())
{
p.Delete();
}
}
};
```

Thank you to (Micah Dail)[https://twitter.com/MicahDail] for creating the script and suggesting it to be included in this document.

0 comments on commit cea68c5

Please sign in to comment.