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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Don-Bot
Helper V
Helper V

Create a new Power BI Report using C# in XMLA Endpoint

I've worked through the Learning TOM code and have successfully created a dataset in Powe BI Service with it.  I can go into it manually and create my own reports from scratch.

 

However, is there a way I can create a power bi report using C# and XMLA Endpoint?  My end goal is to publish the dataset I can now create with it's own blank report that users can just edit and adjust on their own in embeded.

 

Here are links I've gone through but I haven't found anything yet.

 

https://github.com/PowerBiDevCamp/Tabular-Object-Model-Tutorial/blob/main/Solution/Exercise04/PBI-To...

https://www.sqlservercentral.com/blogs/power-bi-meets-programmability-tom-xmla-and-c

https://www.powerbidevcamp.net/articles/programming-datasets-with-TOM/

1 ACCEPTED SOLUTION

Thank you for the reply @lbendlin I was actually able to accomplish this utilizing REST API scripts.  Although now I am working on how to create an access token programmatically.  

 

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;


namespace Learning_TOM
{
    internal class ReportClone
    {
        static readonly HttpClient client = new HttpClient();

        public static async Task callReportCloneRestAPI()

        {
            
            try
            {
                var reportName = "REPORT_NAME";
                var reportID = "REPORT_ID";
                var targetModelID = "MODEL_ID";
                var targetWorkspaceID = "WORKSPACE_ID";
                var bearer = "TOKEN";

                var url = $"https://api.powerbi.com/v1.0/myorg/reports/{reportID}/Clone";
                var data = "{\r\n  \"name\": \"" + reportName + "\",\r\n  \"targetModelId\": \"" + targetModelID + "\",\r\n  \"targetWorkspaceId\": \"" + targetWorkspaceID + "\"\r\n}";
               

                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + bearer);

                var content = new StringContent(data, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.PostAsync(url, content);

                response.EnsureSuccessStatusCode();

                string responseBody = await response.Content.ReadAsStringAsync();

                Console.WriteLine(responseBody);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error copying reports: " + ex.Message);
                Console.ResetColor();
            }
        }

    
    }
}

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Look at reports in notebooks. They use some AI functions for a basic report layout based on the provided data.

 

Announcing Power BI in Jupyter notebooks | Microsoft Power BI Blog | Microsoft Power BI

Thank you for the reply @lbendlin I was actually able to accomplish this utilizing REST API scripts.  Although now I am working on how to create an access token programmatically.  

 

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;


namespace Learning_TOM
{
    internal class ReportClone
    {
        static readonly HttpClient client = new HttpClient();

        public static async Task callReportCloneRestAPI()

        {
            
            try
            {
                var reportName = "REPORT_NAME";
                var reportID = "REPORT_ID";
                var targetModelID = "MODEL_ID";
                var targetWorkspaceID = "WORKSPACE_ID";
                var bearer = "TOKEN";

                var url = $"https://api.powerbi.com/v1.0/myorg/reports/{reportID}/Clone";
                var data = "{\r\n  \"name\": \"" + reportName + "\",\r\n  \"targetModelId\": \"" + targetModelID + "\",\r\n  \"targetWorkspaceId\": \"" + targetWorkspaceID + "\"\r\n}";
               

                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + bearer);

                var content = new StringContent(data, Encoding.UTF8, "application/json");

                HttpResponseMessage response = await client.PostAsync(url, content);

                response.EnsureSuccessStatusCode();

                string responseBody = await response.Content.ReadAsStringAsync();

                Console.WriteLine(responseBody);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error copying reports: " + ex.Message);
                Console.ResetColor();
            }
        }

    
    }
}

I thought your request was for creating a report from scratch, rather than cloning a report.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.