Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added script to handle inc refresh hydration #90

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading