model optimization
16 TopicsDP-600 Study Companion Notebook for Microsoft Fabric
I created this study companion notebook while preparing for the DP-600: Implementing Analytics Solutions Using Microsoft Fabric certification. The repository brings together key Microsoft Fabric concepts including OneLake, Lakehouse, Data Warehouse, Direct Lake, Semantic Models, DAX, Security, Governance, and Monitoring in a single reference guide. The goal is to help analytics engineers, Power BI developers, and certification candidates understand Fabric architecture through practical notes, diagrams, and notebook-based examples. Repository: https://github.com/sabledattatray/dp600-study-companion-notebook Feedback and suggestions are welcome. I hope this resource helps others on their Microsoft Fabric learning journey. https%3A%2F%2Fgithub.com%2Fsabledattatray%2Fdp600-study-companion-notebook1.3KViews1like1CommentSemantic Link - Power BI Fixer
π§ Power BI Fixer β The All-in-One Development Environment for Power BI in Fabric Author: Alexander Korn Β· Solution Engineer Data Platform @ Microsoft Repository: github.com/KornAlexander/semantic-link-labs (branch: feature/pbi-fixer-ui) Website: actionablereporting.com/pbi-fixer Built on: Semantic Link Labs by Michael Kovalsky π Abstract The Power BI Fixer is an interactive development environment that runs natively inside Microsoft Fabric Notebooks. It combines Semantic Link, ipywidgets, and TOM (Tabular Object Model) to provide a comprehensive tool for scanning, exploring, fixing, and documenting Power BI reports and semantic models β all from a single notebook cell. The Problem It Solves Power BI developers face a fragmented workflow: Report issues (pie charts, missing data labels, page sizes) require manual visual-by-visual fixes in Power BI Desktop Model best practices (missing descriptions, floating point types, foreign key visibility) need Tabular Editor or manual scripting No single tool lets you scan a report AND its underlying model, see the results side-by-side, and fix everything in one workflow PBIR format adoption is slow because upgrade tooling is scattered The PBI Fixer addresses all of these by providing 12+ interactive tabs, 17 report fixers, 25+ semantic model fixers, and a unified scan-and-fix workflow β running entirely in a Fabric Notebook. ~17,000 lines of new Python code across 5 UI & tab modules (9,439 lines β incl. Fix All, Model Explorer, Report Explorer, Prototype, Translations, Model Diagram, About), 15 report fixers (3,038 lines), 4 report helpers (593 lines), and 33 semantic model fixers (3,797 lines) β all written from scratch for this project. π¬ Demo Video Watch the full walkthrough: Power BI Fixer v2 Demo on YouTube https%3A%2F%2Fgithub.com%2FKornAlexander%2Fpbi_fixer%2Fblob%2Fmain%2F2026_SemanticLink_AlexanderKorn_PowerBIFixer.ipynb706Views3likes0CommentsAutomated Static RLS Role Management for Power BI Semantic Models
Dynamic RLS is the go-to solution when Power BI security requirements are complex β multiple dimensions, multiple filters, users mapped to many combinations. But on large fact tables it evaluates USERPRINCIPALNAME() on every query for every user, and at scale that cost is significant. This notebook takes a different approach: it reads an RLS mapping table from your Lakehouse, generates static roles automatically, applies DAX filters on dimension tables (letting relationships propagate to fact tables), and assigns members by UPN email β all programmatically via the Tabular Object Model (TOM). ββββββββββββββββββββββββββββββββββββββββ WHAT IT DOES ββββββββββββββββββββββββββββββββββββββββ β Reads distinct security values from a Spark DataFrame (e.g. Country, Brand, Company) and generates one role per value β Applies role-specific DAX filters on dimension tables (DT_*), not fact tables β filters propagate through relationships automatically β Supports global filters applied to every role on their own fixed table (e.g. a consolidation flag always on DT_Customer, an active flag on DT_Product) β Handles create-or-replace β safe to re-run at any time, existing roles are removed and recreated cleanly β Adds members from a Username (UPN) column, saving one member at a time to isolate invalid UPNs without blocking valid ones β Exports a JSON failure report to Lakehouse Files for any members that could not be saved β Supports partial runs via config_keys β process only the dimensions you need ββββββββββββββββββββββββββββββββββββββββ REQUIREMENTS ββββββββββββββββββββββββββββββββββββββββ - Microsoft Fabric workspace with Lakehouse attached to the notebook - Power BI Semantic Model published to the workspace - XMLA Read/Write enabled on the Fabric capacity - semantic-link-labs (installed automatically via %pip install) - RLS source table with: Username (UPN email) + one column per secured dimension ββββββββββββββββββββββββββββββββββββββββ STATIC VS DYNAMIC RLS β WHY IT MATTERS ββββββββββββββββββββββββββββββββββββββββ Static roles are evaluated once at connection time. Dynamic RLS evaluates on every query. On a 10M row fact table with hundreds of security combinations across Country, Brand, and Company β the difference is felt immediately by end users. This notebook makes generating and maintaining hundreds of static roles as straightforward as running two cells. https%3A%2F%2Fgithub.com%2Fenekoegiguren%2Frls_role_management_tmdl642Views2likes1CommentBPA + Memory Analyzer + Write to Lakehouse
This script runs the built-in Notebooks for Semantic Model Health Check Sequential: 1. Best Practice Analyzer (BPA) 2. Memory Analyzer (equivalent to Vertipaq Analyzer 3. Added Bonus: The Resultset of the BPA + Three DAX INFO View tables are saved into a Lakehouse Process: 1. Create Lakehouse 2. Add Lakehouse to Notebook 3. Modify in the Python script the configuration for your Lakehouse Name, Workspace Name and Semantic Model Name 4. Run the Script 5. Check the result directly in the notebook or with the SQL Endpoint in your warehouse import sempy.fabric as fabric from datetime import datetime import re import pandas as pd # ============================================================================ # CONFIGURATION # ============================================================================ dataset = "Semantic Model Name" workspace = "Workspace Name" lakehouse = "Lakehouse_Name" # Function to clean column names def clean_column_name(col_name): col_name = str(col_name).replace('[', '').replace(']', '') col_name = col_name.replace(' ', '_') col_name = re.sub(r'[,;{}()\n\t=]', '', col_name) return col_name # Function to save DataFrame with smart append/overwrite def save_to_lakehouse(df, table_name, description="results"): """ Saves DataFrame to lakehouse. Tries append first, creates table if needed. """ full_table_name = f"{lakehouse}.{table_name}" # Convert pandas to Spark if needed if isinstance(df, pd.DataFrame): spark_df = spark.createDataFrame(df) else: spark_df = df print(f"Saving {description}...") try: # Try append first spark_df.write \ .format("delta") \ .mode("append") \ .option("mergeSchema", "true") \ .saveAsTable(full_table_name) print(f"β Appended {len(df)} records") except: # Table doesn't exist, create it spark_df.write \ .format("delta") \ .mode("overwrite") \ .option("overwriteSchema", "true") \ .saveAsTable(full_table_name) print(f"β Created table with {len(df)} records") # Function to process DAX results with metadata and timestamp handling def process_dax_results(results, dataset, workspace, table_name, description): """ Processes DAX query results: adds metadata, cleans columns, handles timestamps """ if results is not None and len(results) > 0: results['analysis_timestamp'] = datetime.now() results['model_name'] = dataset results['workspace_name'] = workspace results.columns = [clean_column_name(col) for col in results.columns] # Handle old timestamps in common date columns for col in ['ModifiedTime', 'RefreshedTime', 'StructureModifiedTime']: if col in results.columns: results[col] = pd.to_datetime(results[col], errors='coerce') results[col] = results[col].where(results[col] > pd.Timestamp('1900-01-01'), None) save_to_lakehouse(results, table_name, description) display(results.head(10)) return True return False print("="*80) print("STEP 1: Running Best Practice Analyzer...") print("="*80) # Run BPA analysis try: bpa_results = fabric.run_model_bpa( dataset=dataset, workspace=workspace, return_dataframe=True ) except TypeError: bpa_results = fabric.run_model_bpa(dataset=dataset, workspace=workspace) if bpa_results is not None and len(bpa_results) > 0: # Add metadata bpa_results['analysis_timestamp'] = datetime.now() bpa_results['model_name'] = dataset bpa_results['workspace_name'] = workspace bpa_results.columns = [clean_column_name(col) for col in bpa_results.columns] # Save to lakehouse save_to_lakehouse(bpa_results, "bpa_analysis_results", "BPA results") print("\nSummary by Severity:") display(bpa_results.groupby('Severity').size()) print("\n" + "="*80) print("STEP 2: Running Model Memory Analyzer...") print("="*80) memory_results = fabric.model_memory_analyzer(dataset=dataset, workspace=workspace) print("\n" + "="*80) print("STEP 3: Capturing Memory & Storage Statistics via DAX...") print("="*80) spark.conf.set("spark.sql.parquet.datetimeRebaseModeInWrite", "CORRECTED") # Define all INFO queries dax_queries = [ ("INFO.TABLES()", "info_tables", "table statistics"), ("INFO.COLUMNS()", "info_columns", "column statistics"), ("INFO.MEASURES()", "info_measures", "measure statistics"), ("INFO.RELATIONSHIPS()", "info_relationships", "relationship statistics"), ("INFO.STORAGETABLES()", "info_storage_tables", "storage table statistics"), ("INFO.STORAGETABLECOLUMNS()", "info_storage_columns", "storage column statistics"), ("INFO.STORAGETABLECOLUMNSEGMENTS()", "info_storage_segments", "storage segment statistics") ] try: for dax_query, table_name, description in dax_queries: print(f"\nGetting {description}...") results = fabric.evaluate_dax( dataset=dataset, workspace=workspace, dax_string=f"EVALUATE {dax_query}" ) process_dax_results(results, dataset, workspace, table_name, description) except Exception as e: print(f"Error: {str(e)}") print("\n" + "="*80) print("β ANALYSIS COMPLETE!") print("="*80) print("β All results saved to lakehouse and queryable via SQL Analytics Endpoint") print("\nTables created:") print(" - bpa_analysis_results") print(" - info_tables") print(" - info_columns") print(" - info_measures") print(" - info_relationships") print(" - info_storage_tables") print(" - info_storage_columns") print(" - info_storage_segments") https%3A%2F%2Fgithub.com%2FKornAlexander%2FPBI-Tools%2Fblob%2Fmain%2FNotebook%2520Gallery%2FBPA%2520%252B%2520Memory%2520Analyzer%2520%252B%2520Save%2520to%2520Lakehouse.ipynb1.5KViews3likes1CommentCities of Tomorrow: Fabric-Ready Urban Sustainability Playbook
ποΈ Findings Summary: Cities of Tomorrow β Urban Growth & Sustainability This project leveraged Python and standard data science libraries (pandas, numpy, matplotlib, seaborn) to perform an exploratory data analysis (EDA) on an urban planning dataset sourced from Kaggle. The mission was to uncover insights into how cities evolve, sustain, and innovate for the future, ultimately aiming to inform city planners and policymakers. πMethodology & Data Quality The analytical workflow involved loading the dataset, conducting extensive Exploratory Data Analysis (EDA), and visualizing key patterns. The data quality was found to be high, with no missing values or duplicates detected across the features. A preliminary statistical review showed the Urban Sustainability Score had a mean of 0.48 and a standard deviation ($\sigma$) of 0.17, indicating moderate variability in current sustainability performance across the studied urban areas. Feature correlation analysis identified several strong relationships between various urban metrics. β Key Sustainability Drivers & Insights The analysis yielded several crucial insights regarding the core drivers of urban sustainability: Balancing Density and Green Space: A strong positive correlation was found between the Population Density (when balanced) and Green Space Ratio with higher sustainability scores. This suggests that cities managing density effectively while preserving ample green areas achieve better outcomes. The Power of Transit: Public Transport Accessibility was identified as a top driver of urban sustainability. Efficient, widespread transit systems are crucial for reducing carbon footprints and improving urban quality of life. Environmental Initiatives: Both Renewable Energy Usage and the Waste Recycling Rate showed significant positive impacts on the sustainability score, confirming the importance of direct environmental policy initiatives. Crucial Social Infrastructure: Cities with a higher Education Index and broader Healthcare Coverage consistently demonstrated better sustainability outcomes. This highlights the essential, supportive role of robust social infrastructure in achieving long-term urban sustainability goals. π―Conclusion The findings underscore the multifaceted nature of urban sustainability, which is driven by a complex interplay of environmental, infrastructural, and social factors. The results provide city planners with actionable areas for strategic focus, specifically in enhancing public transit, prioritizing green infrastructure, and investing in core social services to build truly sustainable "Cities of Tomorrow." β https%3A%2F%2Fgithub.com%2FSkarthikak%2FPython-Docs%2Fblob%2Fbb8118f8483e3d34ad99425118d6ed50bf9e198c%2FNov2025_%255BSaikarthikAK%255D_CitiesOfTomorrow.ipynb368Views2likes0CommentsOptimize Power BI Report with Model Best Practice Analyzer and Vertipaq Analyzer using Semantic Link
Every Power BI Developer pays attention to the underlying performance of their dashboard beyond just churning out reports. This is why adhering to best practices rules should no longer feel like a task, irrespective of your level of experience with Power BI. Semantic Link Labs is here to get the job done. If you are reading about Semantic Link Labs for the first time, you can read my demo introductory article here. This is a Python library developed by Michael Kovalsky that makes this process easier with just a few lines of code in Microsoft Fabric Notebook. Our Use Case: David, A Power BI developer at the AMA enterprise, got several complaints from colleagues that the Sales and Return dashboards take too long to load and sometimes time out. David thought of many reasons why this could have happened, but he wants to start by using the Model Best Practice Analyser Method and Vertipaq Analyzer to investigate the issue. Before this day, David knew he could use an external tool like Tabular Editor for this task. But he recently found out about a new Python library called Semantic Link Lab using Microsoft Fabric Notebook that can help him figure out this issue with the report with just a few lines of code. The sample Sales & Returns Sample v201912 dashboard use for this demo is available for download here You can also download this Microsoft Fabric Notebook used for this Demo here. Davidβs Task: Perform a Model Best Practice Analyser (BPA) on the Semantic Model of your Power BI report. Perform a Vertipaq Analyzer on your semantic model. Letβs get started: Open your Notebook In Microsoft Fabric, let's investigate what went wrong. Before we get started, we must make sure we have the Semantic Link Labs library installed as well as the other necessary libraries. #Install the Semantic link Labs library in your Fabric notebook %pip install semantic-link-labs After that, we will also be installing the necessary libraries in your notebook. ### Once installed, run this code to import the library into your notebook import sempy_labs as labs from sempy_labs import report as rep from sempy_labs.report import ReportWrapper 1. Performance Model Best Practice Analyzer (BPA) on a Semantic Model report. Model Best Practice Analyzer uses best practice rules to scan your semantic models for bad DAX code, improper formatting and usage of data types, inappropriate relationships, and potentially risky calculation patterns that should be fixed in your report. #Model Best Practice Analyzer import sempy_labs as labs # Enter the name or ID of your semantic model dataset = 'Sales & Returns Sample v201912' # Enter the name or ID of the workspace in which the semantic model # resides workspace = 'Fabricday' labs.run_model_bpa(dataset=dataset, workspace=workspace) When you toggle on the results below, we can see that we have: 16 DAX expression with high rule violation severity, 10 Medium severity, report pages with other details in the Sales & Return Sample v201912 Dashboard. 64 Formatting Medium rule violation severity and 41 on low-level/hints severity. 146 Maintenance low-level/hints rule violation severity and 10 Medium rule violation severity. 46 Performance Medium rule violation severity. & Returns Sample v201912 2. Perform a Vertipaq Analyzer on your Semantic Model. import sempy_labs as labs # Enter the name or ID of your semantic model dataset = 'Sales & Returns Sample v201912' # Enter the name or ID of the workspace in which the semantic model # resides workspace = 'Fabricday' #x = labs.vertipaq_analyzer(dataset=dataset, workspace=workspace) # Setting export='table' will export the results to delta tables in # the lakehouse attached to the notebook x = labs.vertipaq_analyzer(dataset=dataset, workspace=workspace, export='table') # Setting export='zip' will export the results to a .zip file in the lakehouse attached to the notebook. # x = labs.vertipaq_analyzer(dataset=dataset, workspace=workspace, export='zip') The result below shows that the Vertipaq Analyzer Analysis of the Sales & Returns Sample v201912 has been exported to a delta table in my Lakehouse. A snapshot of the Vertipaq Analyzer in my Lakehouse. This shows the Vertipaq Analyzer columns, hierarchies, tables, model, partitions, relationships and tables which can be visualize to understand the semantic model performances. Conclusion If you ever have a slow Power BI Dashboard that takes time to load, and you want to understand the reason for the slow performance. You can download the Microsoft Fabric Notebook used for this optimisation and enhancement Power BI report with Semantic Link Labs here. References Semantic Link Labs Git Hub Repository by Michael Kovalsky: https://github.com/microsoft/semantic-link-labs Feel free to connect with me via my socials below if you want to discuss further. LinkedIn: Musili Adebayo Twitter: Musili_Adebayo https%3A%2F%2Fgithub.com%2FMusili-Adebayo%2F-Musili-Adebayo-fabric_day_project_dashboard%2Fblob%2Fmain%2Fpowerbi_report_notebook.ipynb7.5KViews41likes3CommentsComposite Model: Direct Lake + Import
Composite Model Deployment: Direct Lake + Import This notebook deploys a Composite Semantic Model based on Direct Lake and Import storage modes. Import tables can come from any supported data source and relationships between Direct Lake on OneLake and Import tables are regular relationships. 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 calculated columns and structuring the table with hierarchies for use in Power BI reports and Excel pivot tables. The feature was announced in Power BI May 2025 release. Requirements: Direct Lake on One Lake semantic model: This model is based on the AzureStorage.DataLake protocol. The model must be created in the Power BI Desktop, otherwise it will use the Sql.Database protocol. Import semantic model: This model will be used as a reference for replacement and deployment. Only the desired tables to be in Import mode are required. XMLA read/write: This will enable the deployment through XMLA endpoint. The permission is enabled at the Capacity level and permissions are managed at the Admin Portal. Libraries The only mandatory library is Semantic Link Labs, a Python library designed for use in Microsoft Fabric notebooks. This library extends the capabilities of Semantic Link 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. Remaining libraries are optional, and are used to export the Composite Model definition file to a Lakehouse. # Install Semantic Link Labs %pip install semantic-link-labs # Required Library import sempy_labs as labs # Optional Libraries import json from notebookutils import fs Parameters All the parameters expect the name or the id of the object, except the import_tables parameter. This one requires a list of names of the tables that will be in Import mode. # 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 Model Definition Process workflow: Capture the original model definition (BIM) files Remove from the Direct Lake file the tables that will be kept in Import mode Add in the Direct Lake file the Import tables based on the Import file definition Deploy the model Existing relationships on the Direct Lake model are persisted. It will fail if the column names are different (between Direct Lake and Import models). # 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) Deployment The deployment is done via XMLA endpoint. It will create or update the model if it already exists. After the deployment, a new connection will be displayed in the Gateway and Cloud Connections section of the Semantic Model Properties. A rebind of the Import tables connection is required, since it cannot rely on Single Sign On as Direct Lake does (this is only required after the first deployment). If a connection already exists for the Import table, just check it on the Map to. Otherwise, create a new connection and then Map to it. After the rebind the semantic model can be refreshed. # 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 ) Optional Steps The steps below are optional. The first one validates if the Import connection has been binded (this step must be done manually after deployment). The last one outptus the Composite Model definition file to a Lakehouse. Analyze Connection Bindings # 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.') Output Model Definition File # 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 ) https%3A%2F%2Fgithub.com%2Fdiego-dsanalytics%2Ffabric-notebooks%2Fblob%2Fmain%2FFiles%2Fcomposite_model.ipynb4.4KViews3likes1CommentEDA on AMAZON ANLYSIS
Purpose & Scenario π This notebook showcases the power of Microsoft Fabric Lakehouse to transform raw e-commerce data into actionable business intelligence. Using the Amazon Sales Data from Kaggle, we simulate a real-world retail analytics scenario where decision-makers need clear, data-driven insights to stay competitive in a fast-moving marketplace. Why this matters E-commerce businesses generate huge volumes of sales, pricing, and customer feedback data every day. The challenge isnβt just storing this dataβitβs turning it into insights fast enough to adapt pricing strategies, optimize discounts, and improve product positioning. Our approach Data ingestion: Imported raw CSV into a Fabric Lakehouse table, ensuring itβs ready for scalable analytics. Exploratory Data Analysis (EDA): Used PySpark for distributed data processing and Pandas for quick tabular exploration. Interactive visual storytelling: Leveraged Plotly to create dynamic, drill-down visualizations that reveal trends, anomalies, and correlations instantly. Business-ready metrics: Identified top-performing product categories, mapped discountβrating relationships, and highlighted potential pricing opportunities. Outcome This end-to-end workflow demonstrates how Fabric unifies storage, processing, and visualizationβreducing friction between raw data and strategic action. The result is an interactive analytics experience that empowers business teams to act today, not next quarter. Link of Kaggle Notebook- Amazon Analysis https%3A%2F%2Fgithub.com%2Fgautam17111%2FNotebooks%2Fblob%2Fmain%2FAmazon%2520Analysis.ipynb1.2KViews3likes0CommentsHow to Use Semantic Link Labs in Microsoft Fabric Notebook (Python Demo Walkthrough)
Working with Power BI reports within Microsoft Fabric Notebook just got a whole lot easier! If you are ever tired of manually completing tasks within Microsoft Fabric or exploring the UI console seems like a lengthy process, especially when working with Power BI reports. The Semantic Link Labs is a Python library designed specifically for you to perform tasks within Microsoft Fabric Notebooks programmatically. This Python Library was developed by Michael Kovalsky and it builds on the foundational capabilities of Semantic Link, introducing enhanced features that enable deeper integration and more seamless workflows within the Fabric ecosystem while leveraging the power of Microsoft Fabric Notebook. Hereβs what you need to know about this amazing Python Library. You donβt need to be a Python Expert before you get started. It's an Open-Source library. It allows you to programmatically access all the artefacts in your Workspace(Semantic Models, Lakehouse, Warehouse, Reports, etc). It showcases the power of Microsoft Fabric notebooks. You can perform over 304+ Functions with this Library. So, letβs explore it? Our Scenario: Anna just joined AMA Enterprise as their Fabric Analytics Engineer, and she has been tasked to do the following tasks leveraging the power of the Semantic Links Labs in Microsoft Fabric Notebook. Result from Adventureworks Dashboard report pages.Result from Adventureworks Dashboard report pages. Result from Adventureworks Dashboard report pages. Result from Adventureworks Dashboard report pages. Result from Adventureworks Dashboard report pages. Result from Adventureworks Dashboard report pages. Result from Adventureworks Dashboard report pages. Annaβs task: Understand the existing report metadata (show how many report pages, visuals in a dashboard, different filters used in the report, bookmarks, etc). Show the frequency of the semantic model object used within reports. Find broken visuals in a Power BI report. Get the sizes of all the semantic models in a workspace. Save a report in Power BI Service as a .pbip file. Credit: The snapshot of the Adventureworks Dashboard used for this demonstration was built by my sister, Rofiat Adebayo. You can download the Microsoft Fabric Notebook used for this Python Demo Walkthrough here. Let's get started: Open your Notebook in Microsoft Fabric, and let's start seeing some of the code examples in action. Before we get started, we must make sure we have the Semantic Link Labs library installed as well as the other necessary libraries. #Install the Semantic link Labs library in your Fabric notebook %pip install semantic-link-labs After that, we will also be installing the necessary libraries in your notebook. ### Once installed, run this code to import the library into your # notebook import sempy_labs as labs from sempy_labs.report import ReportWrapper import sempy.fabric as fabric 1. Understand the existing report metadata (show how many report pages, visuals in a dashboard, different filters used in the report, bookmarks, etc). Note: This function require the report to be in the PBIR format. #View Report Metadata report = 'Adventureworks Dashboard' # Name or ID of the report # Name or ID of the workspace in which the report resides workspace = 'Fabricday' rpt = ReportWrapper(report=report, workspace=workspace) # To view the report pages rpt.list_pages() #To list all visual in a dashboard #rpt.list_visuals() #To list all custom visual in a dashboard #rpt.list_custom_visuals() #To list all report filters in a dashboard #rpt.list_report_filters() #To list all page filters in a dashboard #rpt.list_page_filters() #To list all visual filters in a dashboard #rpt.list_visual_filters() #To list all visual objects in a dashboard #rpt.list_visual_objects() #To list all bookmarks in a dashboard #rpt.list_bookmarks() #To list all report level measures in a dashboard #rpt.list_report_level_measures() #To list the semantic model objects in a dashboard #rpt.list_semantic_model_objects() The result shows that we have 11 report pages with other details about the Adventureworks Dashboard. 2. Show the frequency of the semantic model object used within reports. Note: This function require the report to be in the PBIR format. # Show the frequency of the semantic model object used within reports. # Enter the name or ID of your semantic model dataset = 'Adventureworks Dashboard' # Enter the name or ID of the workspace in which the semantic model resides workspace = 'Fabricday' df = labs.list_semantic_model_object_report_usage(dataset=dataset, workspace=workspace, include_dependencies=True, extended=True) display(df) The result below shows that Order Quantity, Product Price, Total Revenue, Total Orders, OrderNumber are the top 5 most used semantic model objects used in the Adventureworks Dashboard. 3. Find broken visuals in a Power BI report. One of Annaβs tasks is to make sure all dashboard works fine and that there are no broken visuals in any of the report pages. Manually scrolling through a 12-page report dashboard seems like a Herculean task since Anna manages 10 other dashboards, too. This is why you can automatically detect broken visuals as a result of changes in measures or calculations with the code below. Note: This function require the report to be in the PBIR format. # Find broken visuals in a Power BI report. import sempy_labs as labs from sempy_labs.report import ReportWrapper # This is for a single report report = 'Adventureworks Dashboard' # The name or ID of the report # The name or ID of the workspace in which the report exists workspace = 'Fabricday' rpt = ReportWrapper(report=report, workspace=workspace) df = rpt.list_semantic_model_objects(extended=True) display(df) The result shows the Valid Semantic Model Object as True because there are no broken visuals in my report, as seen from the GIF I had shared earlier. But if they are broken visuals, Valid Semantic Model Object will be False. 4. Find the sizes of the semantic model. Knowing the size of a semantic model can help Anna to effectively manage her Team Microsoft Fabric capacity and licenses. # Get the size of a semantic model import sempy_labs as labs import sempy.fabric as fabric # Enter the name or ID of your semantic model dataset = 'Adventureworks Dashboard' # Enter the name or ID of the workspace in which the semantic model # resides workspace = 'Fabricday' # To check for a single semantic model model_size = labs.get_semantic_model_size(dataset=dataset, workspace=workspace) display(model_size) The result shows that the total size of the Adventureworks >>> semantic model is 7761847.496032715 4b. To check the size of all the semantic models in the Fabricday my workspace. # Check for all semantic models within a workspace # importing the necessary library import sempy_labs as labs import sempy.fabric as fabric # Enter the name or ID of the workspace in which the semantic model #resides workspace = 'Fabricday' model_sizes = {} dfD = fabric.list_datasets(workspace=workspace, mode="rest") for _, r in dfD.iterrows(): d_name = r["Dataset Name"] d_id = r["Dataset Id"] if not labs.is_default_semantic_model(dataset=d_id, workspace=workspace): model_size = labs.get_semantic_model_size(dataset=d_id, workspace=workspace) model_sizes[d_name] = model_size display(model_sizes) The result shows the sizes of the two semantic models I have in my Fabricday workspace. 5. Save a report in Power BI Service as a .pbip file. Saving a report as .pbip file encourages team collaboration, source control and CI/CD for a Power BI dashboard. It also allows you to easily do a batch update on the item definition on your report, visuals and semantic models. # Saving a report as .pbib file import sempy_labs.report as rep # Name or ID of the report report = 'Sales & Returns Sample v201912' # Name or ID of the workspace in which the report resides workspace = 'Fabricday' # If set to True, saves the report and underlying semantic model. If # set to False, saves just the report. thick_report = True # If set to True, saves a .pbip live-connected to the workspace in # the Power BI / Fabric service. If set to False, saves a .pbip with # a local model, independent from the Power BI / Fabric service. live_connect = True # Enter the name or ID of the lakehouse where you want to save the #.pbip file lakehouse = 'new_fabric_day_lakehouse' # Enter the name or ID of the workspace in which the lakehouse # exists workspace = 'Fabricday' lakehouse_workspace = None rep.save_report_as_pbip(report=report, workspace=workspace, thick_report=thick_report, live_connect=live_connect, lakehouse=lakehouse, lakehouse_workspace=lakehouse_workspace) The result shows the sampleSales & Returns Sample v201912 has been saved as .pbip file in the File section of my lakehouse. Conclusion Working with Power Report and Semantic models in Microsoft fabric just got easier with Semantic link labs. You can download the Microsoft Fabric Notebook used for this Python Demo Walkthrough here. References Semantic Link Labs Git Hub Repository by Michael Kovalsky: https://github.com/microsoft/semantic-link-labs You can connect with me via my socials below if you want to discuss further. LinkedIn: Musili Adebayo Twitter: Musili_Adebayo https%3A%2F%2Fgithub.com%2FMusili-Adebayo%2F-Musili-Adebayo-fabric_day_project_dashboard%2Fblob%2Fmain%2Ffabric_day_nb.ipynb10KViews31likes0CommentsSemantic Model Audit
Link to Notebook Overview This tool is designed to provide a comprehensive audit of your Fabric semantic models. Key Features Model Object & Metadata Capture: Retrieves and standardizes the latest columns and measures using Semantic Link and Semantic Link Labs. Captures dependencies among model objects to get a comprehensive view of object usage. Query Log Collection: Captures both summary query counts and detailed DAX query logs. Unused Column Identification: Compares lakehouse/warehouse and model metadata to identify unused columns in your model's source lakehouse/warehouse. Removing unused columns will result in greater data compression and performance. Cold Cache & Resident Statistics: Deploys a cloned model to measure cold cache performance. Records detailed resident statistics (e.g., memory load, sizes) for each column. Star Schema Generation: Produces a set of star schema tables, making it easy to integrate with reporting tools. https%3A%2F%2Fgithub.com%2Fmicrosoft%2Ffabric-toolbox%2Fblob%2Fmain%2Ftools%2FSemanticModelAudit%2Fnotebook%2FSemanticModelAudit.ipynb6.4KViews2likes3Comments