<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Composite Model: Direct Lake + Import in Notebook Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Notebook-Gallery/Composite-Model-Direct-Lake-Import/m-p/4805306#M55</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H1&gt;&amp;nbsp;&lt;/H1&gt;&lt;H1&gt;Composite Model Deployment: Direct Lake + Import&lt;/H1&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This notebook deploys a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Composite Semantic Model&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;based on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Direct Lake&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Import&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;storage modes. Import tables can come from any supported data source and relationships between Direct Lake on OneLake and Import tables are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;regular relationships&lt;/STRONG&gt;. Small dimension or lookup tables already in Direct Lake storage mode can instead use import storage mode, giving you the option to extend the table with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;calculated columns&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and structuring the table with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;hierarchies&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for use in Power BI reports and Excel pivot tables. The feature was announced in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://powerbi.microsoft.com/en-us/blog/power-bi-may-2025-feature-summary/#post-29934-_Toc119482792" target="_blank" rel="noopener"&gt;Power BI May 2025&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;release.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Requirements:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Direct Lake on One Lake semantic model:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This model is based on the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;AzureStorage.DataLake&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;protocol. The model must be created in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Power BI Desktop&lt;/STRONG&gt;, otherwise it will use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Sql.Database&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;protocol.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Import semantic model:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This model will be used as a reference for replacement and deployment. Only the desired tables to be in Import mode are required.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;XMLA read/write:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This will enable the deployment through XMLA endpoint. The permission is enabled at the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Capacity level&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and permissions are managed at the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Admin Portal&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Libraries&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;mandatory&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;library is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Semantic Link Labs&lt;/STRONG&gt;, a Python library designed for use in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Microsoft Fabric notebooks&lt;/STRONG&gt;. This library extends the capabilities of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Semantic Link&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;offering additional functionalities to seamlessly integrate and work alongside it. In this notebook, Semantic Link Labs is used to capture the reference models definition files and to create/update the Composite Model.&lt;/P&gt;&lt;P&gt;Remaining libraries are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;optional&lt;/STRONG&gt;, and are used to export the Composite Model definition file to a Lakehouse.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;# Install Semantic Link Labs
%pip install semantic-link-labs
     
# Required Library
import sempy_labs as labs

# Optional Libraries
import json
from notebookutils import fs&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Parameters&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the parameters expect the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the object, except the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;import_tables&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;parameter. This one requires a list of names of the tables that will be in Import mode.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Required parameters
workspace = 'ws_demo'                           # Reference workspace

dataset_import = 'sm_import'                    # Source: Import model
dataset_directlake ='sm_directlake'             # Source: Direct Lake model
dataset_composite = 'sm_composite'              # Sink: Composite model

import_tables = ['table1', 'table2', 'table3']  # List of tables that will be set to Import mode

# Optional parameters
storage = 'lh_demo'                             # Lakehouse to ouput the Composite Model definition file&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Model Definition&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Process workflow:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Capture the original model definition (BIM) files&lt;/LI&gt;&lt;LI&gt;Remove from the Direct Lake file the tables that will be kept in Import mode&lt;/LI&gt;&lt;LI&gt;Add in the Direct Lake file the Import tables based on the Import file definition&lt;/LI&gt;&lt;LI&gt;Deploy the model&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Existing relationships on the Direct Lake model are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;persisted&lt;/STRONG&gt;. It will fail if the column names are different (between Direct Lake and Import models).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Get Model Definition file (BIM) from source models
bim_import = labs.get_semantic_model_bim( dataset = dataset_import, workspace = workspace )
bim_directlake = labs.get_semantic_model_bim( dataset = dataset_directlake, workspace = workspace )

# Delete the tables that will change storage mode from the Direct Lake file
bim_directlake['model']['tables'] = [
    table for table in bim_directlake['model']['tables'] 
    if table['name'] not in import_tables
]

# Include the tables with changed storage mode to Import in the Direct Lake file
for table in bim_import['model']['tables']:
    if table['name'] in import_tables:
        bim_directlake['model']['tables'].append(table)&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Deployment&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The deployment is done via&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;XMLA endpoint&lt;/STRONG&gt;. It will create or update the model if it already exists. After the deployment, a new connection will be displayed in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Gateway and Cloud Connections&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;section of the Semantic Model Properties. A&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;rebind&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the Import tables connection is required, since it cannot rely on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Single Sign On&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as Direct Lake does (this is only required after the first deployment).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If a connection already exists for the Import table, just check it on the Map to.&lt;/LI&gt;&lt;LI&gt;Otherwise, create a new connection and then Map to it.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;After the rebind the semantic model can be&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;refreshed&lt;/STRONG&gt;.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Create/Update the Composite Model
try:
    labs.create_semantic_model_from_bim( dataset = dataset_composite, bim_file = bim_directlake, workspace = workspace )
except:
    labs.update_semantic_model_from_bim( dataset = dataset_composite, bim_file = bim_directlake, workspace = workspace )&lt;/LI-CODE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Optional Steps&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The steps below are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;optional&lt;/STRONG&gt;.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The first one validates if the Import connection has been&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;binded&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(this step must be done manually after deployment).&lt;/LI&gt;&lt;LI&gt;The last one outptus the Composite Model definition file to a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Lakehouse&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;H3&gt;Analyze Connection Bindings&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;# Retrieves the list of connections visible in the Fabric environment
connections = labs.list_connections()

# Retrieves the list of connection dependencies in the Semantic Model
model_connections = labs.list_item_connections( item_name = dataset_composite, item_type = 'SemanticModel', workspace = workspace )

# Connections that do not rely on AzureDataLakeStorage (Direct Lake on Onelake)
connection_ids = model_connections[ model_connections['Connection Type'] != 'AzureDataLakeStorage' ]['Connection Id']

for con in connection_ids:
    connection_path = model_connections[ model_connections['Connection Id'] == con ]['Connection Path'].iloc[0]

    if con:
        connection_name = connections[ connections['Connection Id'] == con ]['Connection Name'].iloc[0]
        print(f'The path {connection_path} has been mapped to the {connection_name} connection.')

    else:
        print(f'No connection found for path {connection_path}. Bind the connection before refreshing the semantic model.')&lt;/LI-CODE&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;H3&gt;Output Model Definition File&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Save model definition to Lakehouse
path = f'abfss://{workspace}@onelake.dfs.fabric.microsoft.com/{storage}.Lakehouse/Files/{dataset_composite}.json'
file = json.dumps( bim_directlake, indent = 2 )

fs.put( path, file, overwrite = True )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="msgUrl hidden"&gt;https%3A%2F%2Fgithub.com%2Fdiego-dsanalytics%2Ffabric-notebooks%2Fblob%2Fmain%2FFiles%2Fcomposite_model.ipynb&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Aug 2025 18:45:53 GMT</pubDate>
    <dc:creator>DiegoScalioni</dc:creator>
    <dc:date>2025-08-22T18:45:53Z</dc:date>
    <item>
      <title>Composite Model: Direct Lake + Import</title>
      <link>https://community.fabric.microsoft.com/t5/Notebook-Gallery/Composite-Model-Direct-Lake-Import/m-p/4805306#M55</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H1&gt;&amp;nbsp;&lt;/H1&gt;&lt;H1&gt;Composite Model Deployment: Direct Lake + Import&lt;/H1&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This notebook deploys a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Composite Semantic Model&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;based on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Direct Lake&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Import&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;storage modes. Import tables can come from any supported data source and relationships between Direct Lake on OneLake and Import tables are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;regular relationships&lt;/STRONG&gt;. Small dimension or lookup tables already in Direct Lake storage mode can instead use import storage mode, giving you the option to extend the table with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;calculated columns&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and structuring the table with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;hierarchies&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for use in Power BI reports and Excel pivot tables. The feature was announced in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://powerbi.microsoft.com/en-us/blog/power-bi-may-2025-feature-summary/#post-29934-_Toc119482792" target="_blank" rel="noopener"&gt;Power BI May 2025&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;release.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Requirements:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Direct Lake on One Lake semantic model:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This model is based on the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;AzureStorage.DataLake&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;protocol. The model must be created in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Power BI Desktop&lt;/STRONG&gt;, otherwise it will use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Sql.Database&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;protocol.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Import semantic model:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This model will be used as a reference for replacement and deployment. Only the desired tables to be in Import mode are required.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;XMLA read/write:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;This will enable the deployment through XMLA endpoint. The permission is enabled at the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Capacity level&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and permissions are managed at the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Admin Portal&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Libraries&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;mandatory&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;library is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Semantic Link Labs&lt;/STRONG&gt;, a Python library designed for use in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Microsoft Fabric notebooks&lt;/STRONG&gt;. This library extends the capabilities of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Semantic Link&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;offering additional functionalities to seamlessly integrate and work alongside it. In this notebook, Semantic Link Labs is used to capture the reference models definition files and to create/update the Composite Model.&lt;/P&gt;&lt;P&gt;Remaining libraries are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;optional&lt;/STRONG&gt;, and are used to export the Composite Model definition file to a Lakehouse.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;# Install Semantic Link Labs
%pip install semantic-link-labs
     
# Required Library
import sempy_labs as labs

# Optional Libraries
import json
from notebookutils import fs&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Parameters&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the parameters expect the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;name&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;id&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the object, except the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;import_tables&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;parameter. This one requires a list of names of the tables that will be in Import mode.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Required parameters
workspace = 'ws_demo'                           # Reference workspace

dataset_import = 'sm_import'                    # Source: Import model
dataset_directlake ='sm_directlake'             # Source: Direct Lake model
dataset_composite = 'sm_composite'              # Sink: Composite model

import_tables = ['table1', 'table2', 'table3']  # List of tables that will be set to Import mode

# Optional parameters
storage = 'lh_demo'                             # Lakehouse to ouput the Composite Model definition file&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Model Definition&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Process workflow:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Capture the original model definition (BIM) files&lt;/LI&gt;&lt;LI&gt;Remove from the Direct Lake file the tables that will be kept in Import mode&lt;/LI&gt;&lt;LI&gt;Add in the Direct Lake file the Import tables based on the Import file definition&lt;/LI&gt;&lt;LI&gt;Deploy the model&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Existing relationships on the Direct Lake model are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;persisted&lt;/STRONG&gt;. It will fail if the column names are different (between Direct Lake and Import models).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Get Model Definition file (BIM) from source models
bim_import = labs.get_semantic_model_bim( dataset = dataset_import, workspace = workspace )
bim_directlake = labs.get_semantic_model_bim( dataset = dataset_directlake, workspace = workspace )

# Delete the tables that will change storage mode from the Direct Lake file
bim_directlake['model']['tables'] = [
    table for table in bim_directlake['model']['tables'] 
    if table['name'] not in import_tables
]

# Include the tables with changed storage mode to Import in the Direct Lake file
for table in bim_import['model']['tables']:
    if table['name'] in import_tables:
        bim_directlake['model']['tables'].append(table)&lt;/LI-CODE&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Deployment&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The deployment is done via&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;XMLA endpoint&lt;/STRONG&gt;. It will create or update the model if it already exists. After the deployment, a new connection will be displayed in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Gateway and Cloud Connections&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;section of the Semantic Model Properties. A&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;rebind&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;of the Import tables connection is required, since it cannot rely on&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Single Sign On&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as Direct Lake does (this is only required after the first deployment).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If a connection already exists for the Import table, just check it on the Map to.&lt;/LI&gt;&lt;LI&gt;Otherwise, create a new connection and then Map to it.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;After the rebind the semantic model can be&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;refreshed&lt;/STRONG&gt;.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Create/Update the Composite Model
try:
    labs.create_semantic_model_from_bim( dataset = dataset_composite, bim_file = bim_directlake, workspace = workspace )
except:
    labs.update_semantic_model_from_bim( dataset = dataset_composite, bim_file = bim_directlake, workspace = workspace )&lt;/LI-CODE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H2&gt;&amp;nbsp;&lt;/H2&gt;&lt;H2&gt;Optional Steps&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The steps below are&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;optional&lt;/STRONG&gt;.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The first one validates if the Import connection has been&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;binded&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(this step must be done manually after deployment).&lt;/LI&gt;&lt;LI&gt;The last one outptus the Composite Model definition file to a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Lakehouse&lt;/STRONG&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;H3&gt;Analyze Connection Bindings&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;# Retrieves the list of connections visible in the Fabric environment
connections = labs.list_connections()

# Retrieves the list of connection dependencies in the Semantic Model
model_connections = labs.list_item_connections( item_name = dataset_composite, item_type = 'SemanticModel', workspace = workspace )

# Connections that do not rely on AzureDataLakeStorage (Direct Lake on Onelake)
connection_ids = model_connections[ model_connections['Connection Type'] != 'AzureDataLakeStorage' ]['Connection Id']

for con in connection_ids:
    connection_path = model_connections[ model_connections['Connection Id'] == con ]['Connection Path'].iloc[0]

    if con:
        connection_name = connections[ connections['Connection Id'] == con ]['Connection Name'].iloc[0]
        print(f'The path {connection_path} has been mapped to the {connection_name} connection.')

    else:
        print(f'No connection found for path {connection_path}. Bind the connection before refreshing the semantic model.')&lt;/LI-CODE&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;H3&gt;Output Model Definition File&lt;/H3&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Save model definition to Lakehouse
path = f'abfss://{workspace}@onelake.dfs.fabric.microsoft.com/{storage}.Lakehouse/Files/{dataset_composite}.json'
file = json.dumps( bim_directlake, indent = 2 )

fs.put( path, file, overwrite = True )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="msgUrl hidden"&gt;https%3A%2F%2Fgithub.com%2Fdiego-dsanalytics%2Ffabric-notebooks%2Fblob%2Fmain%2FFiles%2Fcomposite_model.ipynb&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2025 18:45:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Notebook-Gallery/Composite-Model-Direct-Lake-Import/m-p/4805306#M55</guid>
      <dc:creator>DiegoScalioni</dc:creator>
      <dc:date>2025-08-22T18:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Composite Model: Direct Lake + Import</title>
      <link>https://community.fabric.microsoft.com/t5/Notebook-Gallery/Composite-Model-Direct-Lake-Import/m-p/4809197#M58</link>
      <description>&lt;P&gt;Outstanding work!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 13:43:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Notebook-Gallery/Composite-Model-Direct-Lake-Import/m-p/4809197#M58</guid>
      <dc:creator>renan_kramer</dc:creator>
      <dc:date>2025-08-27T13:43:46Z</dc:date>
    </item>
  </channel>
</rss>

