Forum Discussion
How to change lakehouse connected to semantic model? Programmatical Approach
- Anonymous1 year ago
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.
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