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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Clampazzo
Resolver I
Resolver I

Create DirectQuery Datasest with XMLA Endpoint doesn't automatically select gateway

I am currently building a directquery dataset via code and xmla endpoint.  I have been able to create the dataset in my workspace however when I navigate to the online dataset it doesn't have the gateway connections automatically set.  I have to then takeover the dataset, navigate to gateways and then it will auto fill out the correct gateway.  

Is there a way I can do this in code?  Below is what I'm seeing and then the code I am using.

 

When first created there are no tables:

Clampazzo_0-1695385260237.png

Then after I navigate to settings, click on take over settings, and open gateway and cloud connections it automatically finds the correct connection and loads it. 

I navigate back and the tables are already filled in.  The only thing I did was takeover and navigate to the connection.  

 

Is there a way I can do this via code so that this is automatically done?

 

  public static void CreateWingtipSalesModel(Database database) {

    Model model = database.Model;

 

          Table tableCustomers = CreateCustomersTable();
  
          model.Tables.Add(tableCustomers);
 

         model.SaveChanges();

    model.RequestRefresh(RefreshType.Full);
    model.SaveChanges();
  }
  
  
    private static Table CreateCustomersTable()
  {

      Table customersTable = new Table()
      {
          Name = "Case",
          Description = "Case table",
          Partitions = {
              new Partition() {
          Name = "All Cases",
          Mode = ModeType.DirectQuery,
          Source = new MPartitionSource() {
              Expression = Properties.Resources.CustomersQuery_m

          }
      }
  },
          Columns = {
      new DataColumn() { Name = "Case_ID", DataType = DataType.Int64, SourceColumn = "Case_ID", IsHidden=false },
      new DataColumn() { Name = "Category", DataType = DataType.String, SourceColumn = "Category" }

  }
      };



      return customersTable;
  }

 

 

The Customers Query M code is below:

let
    Source = Sql.Database("CONNECTION", "DATABASE", [MultiSubnetFailover=true]),
    FieldProc_vwCase = Source{[Schema="dbo",Item="table"]}[Data]
in
    dbo_table
1 REPLY 1
lbendlin
Super User
Super User

If this is important to you please consider voting for an existing idea or raising a new one at https://ideas.fabric.microsoft.com/?forum=2d80fd4a-16cb-4189-896b-e0dac5e08b41

 

Also this: Datasets - Take Over In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.