Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
BartHuls
Helper I
Helper I

Uploading a PBIX file with PostImportWithFileAsyncInGroup does not return datasets

I'm trying to upload a Symantic Model in a PowerBi Workspace, using the c# PowerBiClient. I'm using the following code:

public async Task<Import> UpsertDataSet(Guid groupId, string path, string displayName)
{
    var pbiClient = await GetPowerBIClient() ?? throw new PowerBiException(PowerBiClientIsNull);

    using var pbixStream = new FileStream(path, FileMode.Open, FileAccess.Read);
    var import = await pbiClient.Imports.PostImportWithFileAsyncInGroup(groupId, pbixStream, displayName, nameConflict: ImportConflictHandlerMode.CreateOrOverwrite);

    return await pbiClient.Imports.GetImportInGroupAsync(groupId, import.Id);
}

There are cases where the import.Datasets are not filled while the Model is uploaded.

I added and extra GetImportInGroupAsync to check if the model is updated. How come that the result is empty when the Model is updated.
I looked into the "Lineage" view and the the time of Refresh looks ok for the Semantic model

 

1 ACCEPTED SOLUTION
v-pnaroju-msft
Community Support
Community Support

Hi @BartHuls,

Thank you for reaching out through the Microsoft Fabric Community Forum.

Based on my understanding, the issue arises because the import operation is asynchronous. The

PostImportWithFileAsyncInGroup method returns an Import object immediately; however, the dataset metadata is not populated until the import process is fully completed. Your GetImportInGroupAsync call checks the status prematurely, before the import has finished, even though the Lineage view indicates that the model has been updated.

Kindly follow the steps below, which may help in resolving the issue:

  1. After initiating the import, continuously poll the import status using GetImportInGroupAsync within a loop.

  2. Monitor the ImportState property until it changes to Succeeded, indicating that the import has been completed.

  3. Once the state is Succeeded, the Datasets property should be populated.

  4. Handle potential edge cases, such as import failures, large PBIX files (which may require additional time), and permission-related issues.

Polling ensures that you wait for the import process to be fully completed, including the population of dataset metadata, before accessing the Datasets property.

Additionally, you may refer to the following links for further details:
Imports - Post Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Imports - Get Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Microsoft.PowerBI.Api Namespace - Azure for .NET Developers | Microsoft Learn

If you find our response helpful, kindly mark it as the accepted solution and provide kudos. This will assist other community members facing similar queries.

Thank you.

View solution in original post

2 REPLIES 2
BartHuls
Helper I
Helper I

I though that this was the case.
I came up with this implementation:

public async Task<Import> UpsertDataSet(Guid groupId, string path, string displayName)
{
    var pbiClient = await GetPowerBIClient() ?? throw new PowerBiException(PowerBiClientIsNull);

    using var pbixStream = new FileStream(path, FileMode.Open, FileAccess.Read);
    var import = await pbiClient.Imports.PostImportWithFileAsyncInGroup(groupId, pbixStream,
        datasetDisplayName: displayName,
        nameConflict: ImportConflictHandlerMode.CreateOrOverwrite,
        overrideModelLabel: true,
        overrideReportLabel: true);

    var importId = import.Id;
    var retry = 0;

    while (retry++ < MaxRetries)
    {
        var importState = ParseImportState(import.ImportState);

        if (importState is ImportState.Succeeded)
        {
            return import;
        }

        if (importState is ImportState.Failed)
        {
            throw new PowerBiException(ImportFailed);
        }

        await Task.Delay(500);

        import = await pbiClient.Imports.GetImportInGroupAsync(groupId, importId);
    }

    throw new PowerBiException(ImportFailed);
}

private static ImportState ParseImportState(string state)
{
    return state switch
    {
        "Succeeded" => ImportState.Succeeded,
        "Failed" => ImportState.Failed,
        "Publishing" => ImportState.Publishing,
        _ => ImportState.Unknown
    };
}




v-pnaroju-msft
Community Support
Community Support

Hi @BartHuls,

Thank you for reaching out through the Microsoft Fabric Community Forum.

Based on my understanding, the issue arises because the import operation is asynchronous. The

PostImportWithFileAsyncInGroup method returns an Import object immediately; however, the dataset metadata is not populated until the import process is fully completed. Your GetImportInGroupAsync call checks the status prematurely, before the import has finished, even though the Lineage view indicates that the model has been updated.

Kindly follow the steps below, which may help in resolving the issue:

  1. After initiating the import, continuously poll the import status using GetImportInGroupAsync within a loop.

  2. Monitor the ImportState property until it changes to Succeeded, indicating that the import has been completed.

  3. Once the state is Succeeded, the Datasets property should be populated.

  4. Handle potential edge cases, such as import failures, large PBIX files (which may require additional time), and permission-related issues.

Polling ensures that you wait for the import process to be fully completed, including the population of dataset metadata, before accessing the Datasets property.

Additionally, you may refer to the following links for further details:
Imports - Post Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Imports - Get Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn
Microsoft.PowerBI.Api Namespace - Azure for .NET Developers | Microsoft Learn

If you find our response helpful, kindly mark it as the accepted solution and provide kudos. This will assist other community members facing similar queries.

Thank you.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.