Forum Discussion

jaryszek's avatar
jaryszek
Icon for Super User rankSuper User
1 year ago
Solved

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 lakehouse...
  • Anonymous's avatar
    Anonymous
    11 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.