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'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.
- jaryszek1 year ago
Super User
wow this is a gold!
I tried to add parameters like here:
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- Anonymous1 year agoNot applicable
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.- jaryszek1 year ago
Super User
ok thank you.
but still has issue:
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