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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Tored
Frequent Visitor

How do I use the enhanced metadata format in C#?

Hello, I would like to automate the DataSet generation (using C#). In this context, I have encountered problems when I create the DataSet in Power BI Service (For more information: Data source information is not found in Power BI service ). For this reason, I am now trying to generate the DataSet within a Power BI file in an open Power BI Desktop instance. In doing so, I am running into an issue with the enhanced metadata format, which is what this thread is about.

 

My situation:

With my C# code, I connect to a PBIX file that is open in Power BI Desktop.
Then I add a new data source and a new table to the DataSet from the PBIX file.
After running the code, the table also appears in Power BI Desktop and I can use it.

 

My problem:
The message pops up (translated from German to English):
"No upgrade to use the enhanced metadata format has been performed for this report. The upgrade is required to make modeling changes."

There is also a button "Perform upgrade for report" and when I press it, my table disappears.

 

image.png

 

My questions:
How can I run such an upgrade (for using the enhanced metadata format) with C# code without my table disappearing afterwards or how do I use the enhanced metadata format in C#?

 

My requirements:
- PPU (Premium Per User) Trial License
- On Premise SQL Server
- Microsoft.AnalysisServices Package

 

My code:

 

 

// Get connection string to PowerBI-File
var connections = PowerBIDesktopUtilities.GetActiveDatasetConnections();
var connectionString = connections[1].ConnectString;

using (Microsoft.AnalysisServices.Tabular.Server server = new Microsoft.AnalysisServices.Tabular.Server())
{
   server.Connect(connectionString);
   var database = server.Databases[0];

   // Adding local SQL Server as data source
   string dataSource = "LocalSQLServer";
   bool expression = database.Model.DataSources.Contains(dataSource);
   if (!expression)
   {
      database.Model.DataSources.Add(new ProviderDataSource()
      {
         //[...]
      });
   }

   // Adding Table
   database.Model.Tables.Add(new Table()
   {
      Name = database.Model.Tables.GetNewName("Individual Customers"),
      Description = "Individual customers (names and email addresses) that purchase Adventure Works Cycles products online.",
      Partitions = {
         //[...]
      },
      Columns =
      { 
         //[...]
      }
   });

   database.Model.RequestRefresh(Microsoft.AnalysisServices.Tabular.RefreshType.Full);
   database.Update(UpdateOptions.ExpandFull);
}

 

 

 

Thanks in advance!

1 REPLY 1
Tored
Frequent Visitor

I have edited my post, which hopefully describes my problem more accurately now.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors