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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jaryszek
Power Participant
Power Participant

How to change lakehouse connected to semantic model? Programmatical Approach

Hello, 

How to change lakehouse connected to semantic model?

So imagine I can have 2 situations:

1. Semantic Model on OneLake flavour connected to lakehouse1

What if i have second lakehouse2 and want to switch current semantic model to it? Assuming that i have the same tables like in old Lakehouse1 plus some news?

2. How can i have a "Baseline" lakehouse and connect to it each time when I am creating a new semantic model and connect to some custome specific lakehouse to use different table? How to make this manually and in programmatic way?

How to make those steps both manually and programmaticaly? 

Best,
Jacek

1 ACCEPTED SOLUTION
v-agajavelly
Community Support
Community Support

Hi @jaryszek ,

The error appears because parameters can only be declared at the model level, not inside tables or partitions. Here’s how to do it correctly.

  • Parameters must go in the model.tmdl file this is the root configuration of your semantic model.
  • You can’t add them directly from the Power BI TMDL editor tab. That view is currently read-only for model-level elements.
  • Use Tabular Editor 3 (or even a simple text editor) to open and edit the TMDL files.

Correct Syntax

In your model.tmdl, define the parameters like this:

model "SalesModel" {

    parameter LakehouseName = "SalesLakehouse"

    parameter WorkspaceId = "abc123xyz"

    culture = "en-US"

    annotations = []

}

Once defined, you can reference those parameters in your table or partition definitions, for example:

table "SalesTable" {

    partition "DirectLake" {

        mode = "DirectLake"

        expression =

            let

                Source = AzureStorage.DataLake(

                    $"https://onelake.dfs.fabric.microsoft.com/{WorkspaceId}/{LakehouseName}",

                    [HierarchicalNavigation = true]

                )

            in

                Source

    }

}

This will works for you. If you try to place parameter inside a table or partition block, you’ll get. The keyword 'parameter' is neither a property nor an object in the current context. That’s because TMDL only recognizes parameters when they’re declared at the model scope.

Keep reusable values like LakehouseName and WorkspaceId in the model file and reference them using $"{WorkspaceId}/{LakehouseName}" it makes your model cleaner and easier to maintain.

Thanks,
Akhil.

View solution in original post

10 REPLIES 10
v-agajavelly
Community Support
Community Support

Hi @jaryszek ,

The error appears because parameters can only be declared at the model level, not inside tables or partitions. Here’s how to do it correctly.

  • Parameters must go in the model.tmdl file this is the root configuration of your semantic model.
  • You can’t add them directly from the Power BI TMDL editor tab. That view is currently read-only for model-level elements.
  • Use Tabular Editor 3 (or even a simple text editor) to open and edit the TMDL files.

Correct Syntax

In your model.tmdl, define the parameters like this:

model "SalesModel" {

    parameter LakehouseName = "SalesLakehouse"

    parameter WorkspaceId = "abc123xyz"

    culture = "en-US"

    annotations = []

}

Once defined, you can reference those parameters in your table or partition definitions, for example:

table "SalesTable" {

    partition "DirectLake" {

        mode = "DirectLake"

        expression =

            let

                Source = AzureStorage.DataLake(

                    $"https://onelake.dfs.fabric.microsoft.com/{WorkspaceId}/{LakehouseName}",

                    [HierarchicalNavigation = true]

                )

            in

                Source

    }

}

This will works for you. If you try to place parameter inside a table or partition block, you’ll get. The keyword 'parameter' is neither a property nor an object in the current context. That’s because TMDL only recognizes parameters when they’re declared at the model scope.

Keep reusable values like LakehouseName and WorkspaceId in the model file and reference them using $"{WorkspaceId}/{LakehouseName}" it makes your model cleaner and easier to maintain.

Thanks,
Akhil.

thank you!

v-agajavelly
Community Support
Community Support

Hi @jaryszek ,

You're absolutely right, it’s not M code. When working with Power BI Studio (VS Code) and TMDL (Tabular Model Definition Language), you're scripting the semantic model directly, not using Power Query. Here's how to approach parameterizing Lakehouse connections.

1. Enable TMDL View in Power BI Desktop (Preview)

    • Go to File > Options and settings > Options > Preview features
    • Enable TMDL View.

2. Define Parameters in TMDL.

    • In your .tmdl file, define parameters like:
parameter LakehouseName = "SalesLakehouse" 
parameter WorkspaceId = "abc123xyz"
    • These parameters can be referenced in your partition expressions or data source definitions.

3. Use Parameters in Data Source.

    • Example for Direct Lake mode:
expression 'SalesTable' = let Source = AzureStorage.DataLake( $"https://onelake.dfs.fabric.microsoft.com/{WorkspaceId}/{LakehouseName}", [HierarchicalNavigation = true] ) in Source
    • This allows you to switch Lakehouse targets by updating parameter values.

4.Deploy with Updated Parameters

  • After editing the .tmdl file, deploy the semantic model using Power BI Studio.
  • You can script and reuse these definitions across environments (e.g., dev → test → prod).

Use Tabular Model Definition Language (TMDL) view in Power BI Desktop - Power BI | Microsoft Learn
Solved: Re: Data Source Parameters in Direct Lake mode - Microsoft Fabric Community

Thanks,
Akhil.

wow this is a gold! 

I tried to add parameters like here:

jaryszek_0-1759310050742.png


but it is showing error: 

TMDL Format Error: Parsing error type - UnknownKeyword Detailed error - The keyword 'parameter' is neither a property nor an object in the current context! Document - '' Line Number - 3 Line - ' parameter LakehouseName = "SalesLakehouse",'


Why? Where to put them?

Best,
Jacek

 

Hi @jaryszek ,

Ah, great follow-up, and that error makes perfect sense. In TMDL, parameters must be declared in the correct context. You can't just drop parameter declarations anywhere in the model file. Here's how to fix it.

Correct Way to Declare Parameters in TMDL.

Parameters should be placed inside the model.tmdl file, not in a table or partition definition. Think of model.tmdl as the root configuration file for your semantic model.

model "SalesModel" { parameter LakehouseName = "SalesLakehouse" parameter WorkspaceId = "abc123xyz" culture = "en-US" annotations = [] }

Then, in your table or partition .tmdl files, you can reference these parameters like this.

table "SalesTable" { partition "DirectLake" { mode = "DirectLake" expression = let Source = AzureStorage.DataLake( $"https://onelake.dfs.fabric.microsoft.com/{WorkspaceId}/{LakehouseName}", [HierarchicalNavigation = true] ) in Source } }

Made Common Mistake by placing parameter inside a table or partition block will trigger the exact error you're seeing.

The keyword 'parameter' is neither a property nor an object in the current context.

Thanks,
Akhil.

ok thank you. 

but still has issue:

jaryszek_0-1759324175819.png



I have open tmdl model like here. 
And trying to add parameters, can I add this from power bi tmdl tab level? 
Or i need to save this using Tabular Editor and add there?

Best,
Jacek



v-agajavelly
Community Support
Community Support

Hi @jaryszek ,

You can’t do it directly in Fabric or Tabular Editor. The only way to rebind an existing report (keeping its ID, subscriptions, etc.) is via Power BI REST API  specifically the Rebind Report In Group endpoint.

  1. To parameterize Lakehouse connection.

Use Power BI Studio (VS Code) with TMDL. Define parameters like LakehouseName and WorkspaceId, then plug them into your data source. Update the values and redeploy to switch sources.

  1. 2. To manually change Lakehouse for a specific table.

Open Tabular Editor, go to the table’s partition, and edit the Lakehouse connection details (workspace ID + lakehouse name). Save and deploy.

That’s the cleanest way to do it REST API for rebinding, Power BI Studio for parameterization, Tabular Editor for table-level tweaks.

Thanks,
Akhil.

thanks.

Do you have any tutorials how to parametrize connection in power bi studio?
It will be not M code I assume?

Best,
Jacek

v-agajavelly
Community Support
Community Support

Hi @jaryszek ,


You can handle this in two ways

Switch semantic model from Lakehouse1 to Lakehouse2

  • Manual: Create a new semantic model pointing to Lakehouse2, add tables, then rebind reports to it.
  • Programmatic: Export model (TMSL/JSON), update the DataSource to Lakehouse2, redeploy, and process the model.

Baseline lakehouse + custom overrides

  • Keep shared tables in a baseline lakehouse.
  • Create semantic models with additional tables from custom lakehouses.
  • Use a template model with parameterized connection info and deploy via script (TMSL/REST API).
  • Multi-source models can reference baseline + custom lakehouse together.

Always check schema compatibility and rebind reports after the switch. Tools like Semantic Link / SemPy or XMLA scripts help automate this.

Thanks,
Akhil.

ok thanks.

"Manual: Create a new semantic model pointing to Lakehouse2, add tables, then rebind reports to it."

How to rebind report manually? From what i know you can use rest apis to do this but this is not manual way...By manual I mean doing this in fabric or Tabular Editor?
Use a template model with parameterized connection info and deploy via script (TMSL/REST API).

"Use a template model with parameterized connection info and deploy via script (TMSL/REST API)."
How to paremetrize connection via rest api and update source tables lakehouse? 

And additional question:
How to change data source lakehouse for specific table manually using Direct Lake over OneLake? 

Best,
Jacek

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.