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.
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
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