Forum Discussion
How to change lakehouse connected to semantic model? Programmatical Approach
- Anonymous11 months 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’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.
- 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.
- 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