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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Don-Bot
Helper V
Helper V

Using XMLA endpoint to copy a dataset but source model is null

I am currently working on utilizing XMLA Endpoint with C# to copy a datamodel that exists in my workspace.

The steps I am following are:

  1. Create the new datamodel with a dummy model
  2. copy the current model over to the new datamodel.
  • This is where I have issues. When I connect to my existing datamodel in Visual Studios the value for model is 'null'.

Can someone direct me to how I can resolve this? Or do I need to recreate the entire model in code other than copy it?

My goal is to have a template datamodel that I will copy to different workspaces and then modify them from there.

I have been working with the below code:

 

 

const string connectString = "powerbi://api.powerbi.com/v1.0/myorg/MYDATAMODEL";
 

static void Main(string[] args) {

    Server server = new Server();
    server.Connect(connectString);
    Model model = server.Databases[0].Model;

 

    string sourceDatabaseName = "DATABASE";
    string DatabaseName = "DATABASE - Copy";

    Database sourceDatabase = server.Databases.GetByName(sourceDatabaseName);

        string newDatabaseName = server.Databases.GetNewName(DatabaseName);
        Database targetDatabase = CreateDatabase(newDatabaseName);
        sourceDatabase.Model.CopyTo(targetDatabase.Model);
        targetDatabase.Model.SaveChanges();

        targetDatabase.Model.RequestRefresh(RefreshType.Full);
        targetDatabase.Model.SaveChanges();

     
     Database CreateDatabase(string DatabaseName)
    {

        string newDatabaseName = server.Databases.GetNewName(DatabaseName);

        var database = new Database()
        {
            Name = newDatabaseName,
            ID = newDatabaseName,
            CompatibilityLevel = 1520,  
            StorageEngineUsed = Microsoft.AnalysisServices.StorageEngineUsed.TabularMetadata,
            Model = new Model()
            {
                Name = DatabaseName + "-Model",
                Description = "A Demo Tabular data model with 1520 compatibility level."
            }
        };

        server.Databases.Add(database);
        database.Update(Microsoft.AnalysisServices.UpdateOptions.ExpandFull);

        return database;
    }

}

 

 

 

nullvalue.png

0 REPLIES 0

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.