Blog Post

Power BI Community Blog
4 MIN READ

Programmatically deploy Semantic Models and Reports via Semantic Link Labs

VivienneVereen's avatar
VivienneVereen
Icon for Microsoft Employee rankMicrosoft Employee
1 year ago

This article is co-authored by Behram Khan and Vivienne Vereen, Architects at Microsoft

 

Looking for governance across semantic models and reports? Need a programmatic solution to deploy Direct Lake (and other) semantic models and reports across workspaces and Lakehouses? Semantic Link Labs is the answer. Thanks to Michael Kovalsky and Markus Cozowicz for their efforts in creating this incredible library! In this article, we will review the Power BI architecture and output of a Fabric notebook that leverages Semantic Link Labs to programmatically deploy semantic models and reports across workspaces and schema-enabled Lakehouses, providing central governance.

 

Steps:

 

  1. Deploy semantic model to new workspace and rename
  2. Update semantic model connection to new Lakehouse
  3. (Optional) Check semantic model Lakehouse connection
  4. Update Direct Lake table partition to new schema
  5. (Optional) Get Tabular Model Scripting Language (TMSL) to confirm lineage
  6. Clone report to new workspace and rebind to new semantic model
  7. (Optional) Launch report to preview

 

Architecture

 

 

Partitioning a semantic model and reports into smaller source tables, for example by store (Europe, Asia, North America) has many benefits including:

 

  • Performance optimization: Reduced row counts improve query performance.
  • Decreased concurrent queries: Subsets of users generate fewer concurrent queries.
  • Simplified security management: Option to eliminate or simplify Row-Level Security (RLS) requirements.

 

In the example below, we have an architecture in which each store has its own schema with shared dimensions (shortcuts within Gold Lakehouse). As best practice semantic models and reports are in separate workspaces and reports are distributed via apps:

  • One Data Engineering – Gold workspace with Lakehouse
  • Three Data Hub workspaces with Lakehouses and Direct Lake Semantic Models
  • Three Reporting Hub workspaces with Reports and Apps

 

 

Within the Data Engineering – Gold workspace we have a schema-enabled Lakehouse with schemas for each store:

 

 

The Fact tables in each schema are directly populated via ETL processes (in this case a simple change in where clause) while dimensions are shared across schemas via shortcuts from the “master” dbo schema.

 

Each Data Hub workspace has their own Reporting Lakehouse with schema shortcuts to their respective schema in the Data Engineering – Gold workspace. Example for Europe shown below:

 

 

 

Now, the goal is to develop three Direct Lake semantic models and reports that point to unique workspaces, Lakehouses and schemas. Instead of having to do this manually each time a change is made to the semantic model or report (which makes for a governance nightmare and leaves a lot of room for error), we will leverage Semantic Link Labs in Fabric notebooks to automate the deployment.

 

Let’s treat the Europe store as the starting point and source of truth for our development. We have a working semantic model and report for Europe and would like to deploy to Asia and North America.

 

 

 

 

 

Programmatic Deployment using Semantic Link Labs

 

The notebook below will programmatically deploy the Europe semantic model and report to Asia and North America across workspaces with different Lakehouses and lineage.

 

 

 

Reviewing the results after running the notebook

 

As seen below, we now have two new semantic models and reports for Asia and North America with updated workspaces and Lakehouses:

 

 

 

Viewing the reports, everything works as expected:

 

 

 Note, a few manual steps remain

 

  • After initial model deployment: need to update security role members, cloud connection from SSO (default) to fixed identity, access permissions.
  • Once deployed and model is overwritten only cloud connection needs to be updated.

However, the above items should be able to be done programmatically via Semantic Link Labs and this is next on my to-do list 🙂

 

1. Adding security role members on the new semantic models:

 

 

2. Updating Cloud connection settings to fixed identity (for RLS purposes):

 

 

3. Updating permissions:

 

 

4. Updating app:

 

 

Reporting Hub – Asia App from TestUser1 perspective with dynamic Product RLS implemented:

 

 

Final Thoughts

 

Coming from a Power BI development background, I’m by no means a Python expert but Semantic Link makes data science and automation accessible to everyone! The extent of capabilities within Semantic Link Labs is truly impressive. Tasks that would have taken hours if not days including testing were done within minutes using minimal scalable code. Give it a try and let me know your thoughts!

 

References

 

 

- Behram KhanVivienne VereenArchitects at Microsoft

Updated 1 year ago
Version 2.0

4 Comments

  • Great Article! I appreciate the depth in which you covered this process.
    I recently implemented a similar solution and came up with a lot of the same approaches.

     

    One question, do you know if there is any benefit from using the clone_report function vs getting the report json and calling create_report_from_json? Maybe just one less API call?

     

    Also, you can update the cloud connection settings programmatically by calling the Datasets - Bind to Gateway in Group API. The trick is getting the gateway ID of the cloud connection. You can look it up, if it is set on your source model. I had issues using the semantic link labs wrapper of this because the gateway APIs don't return the cloud gateway.

  • Anonymous's avatar
    Anonymous
    Not applicable

    We were sucessfully using generate_direct_lake_semantic_model but with the advent of schemas in lakehouses this now fails. Is there any advice on this?

  • Anonymous 

     

    What is the error you are receiving. The generate_direct_lake_semantic_model has a schema parameter which defaults to dbo. Are you setting that correctly for the lakehouse you are referencing?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi npergand

     

    Thanks for your reply.

     

    Using this:

        from sempy_labs.directlake import generate_direct_lake_semantic_model, add_table_to_direct_lake_semantic_model
     

    The error is:

    When I call this: 

     
            generate_direct_lake_semantic_model(
                dataset             = p_model_name,
                lakehouse_tables    = p_source_tables,
                lakehouse           = p_lakehouse_name,
                lakehouse_workspace = p_lakehouse_workspace,
                schema              = p_lakehouse_schema,
                workspace           = p_workspace_name,
                refresh             = True,
                overwrite           = True 
     
    I am using thre schema parameter and these are the values I pass: 
    p_lakehouse_schema = "xx"
    v_source_tables       = ["aaaa", "bbbb", "cccc"]
     
    I do not beleive it is the values that cause the error but am happy to be proved wrong.
    The code worked when not using schemas and now we are it does not.
    I do populate the schema parameter.
    The error is: The operation is not supported for Lakehouse with schemas enabled
     
    I would be interested in your thoughts?