mikova's avatar
mikova
Microsoft Employee
1 year ago

Report Analysis

Download this notebook from: semantic-link-labs/notebooks/Report Analysis.ipynb at main · microsoft/semantic-link-labs · GitHub

 

Install the latest .whl package

Check here to see the latest version.

%pip install semantic-link-labs

Import the library and set the initial parameters

import sempy_labs as labs
import sempy_labs.report as rep
from sempy_labs.report import ReportWrapper

# For checking reports
report_name = '' # Enter the report name
report_workspace = None # Enter the workspace in which the report exists
rpt = ReportWrapper(report=report_name, workspace=report_workspace)

Report Best Practice Analyzer (BPA)

rep.run_report_bpa(report=report_name, workspace=report_workspace)

Report BPA using custom rules

import pandas as pd

rules = pd.DataFrame(
    [
        (
            "Error Prevention",
            "Semantic Model",
            "Error",
            "Fix report objects which reference invalid semantic model objects",
            lambda df: df["Valid Semantic Model Object"] == False,
            "This rule highlights visuals, report filters, page filters or visual filters which reference an invalid semantic model object (i.e Measure/Column/Hierarchy).",
            "",
        ),
        (
            "Performance",
            "Page",
            "Warning",
            "Reduce the number of visible visuals on the page",
            lambda df: df["Visible Visual Count"] > 15,
            'Reducing the number of visable visuals on a page will lead to faster report performance. This rule flags pages with over " + visVisuals + " visible visuals.',
        ),
        (
            "Performance",
            "Visual",
            "Warning",
            "Reduce the number of objects within visuals",
            lambda df: df["Visual Object Count"] > 5,
            "Reducing the number of objects (i.e. measures, columns) which are used in a visual will lead to faster report performance.",
        )
    ],
    columns=[
        "Category",
        "Scope",
        "Severity",
        "Rule Name",
        "Expression",
        "Description",
        "URL",
    ],
)

rep.run_report_bpa(report=report_name, workspace=report_workspace, rules=rules)

View all semantic model objects within a report

rpt.list_semantic_model_objects()

View broken report objects (if any semantic model objects used in the report do not exist within the semantic model)

The 'Valid Object' column indicates if the object (measure/column/hierarchy) exists within the semantic model used by the report

rpt.list_semantic_model_objects(extended=True)

View broken report objects across all reports tied to a semantic model

dataset_name = '' # Enter the semantic model name
dataset_workspace = None # Enter the workspace name in which the semantic model exists (if set to None it will use the workspace in which the notebook is running)
labs.list_report_semantic_model_objects(dataset=dataset_name, workspace=dataset_workspace, extended=True)

List functions within the ReportWrapper

rpt.list_custom_visuals()
rpt.list_pages()
rpt.list_visuals()
rpt.list_visual_objects()
rpt.list_report_filters()
rpt.list_page_filters()
rpt.list_visual_filters()
rpt.list_report_level_measures()
rpt.list_visual_interactions()
rpt.list_bookmarks()

Perform actions on a report

Set a custom theme for a report based on a Power BI theme file

rpt.set_theme(theme_file_path='/lakehouse/default/Files/CY23SU09.json')
rpt.set_theme(theme_file_path='https://raw.githubusercontent.com/PowerBiDevCamp/FabricUserApiDemo/main/FabricUserApiDemo/DefinitionTemplates/Shared/Reports/StaticResources/SharedResources/BaseThemes/CY23SU08.json')

Set whether a Power BI report page is hidden or visible

rpt.set_page_visibility(page_name='Page 1', hidden=True)

Set the active page (page shown upon opening the report)

rpt.set_active_page(page_name='Page 2')

Disable the 'show items with no data' for all visuals within a Power BI report

rpt.disable_show_items_with_no_data()

Remove all custom visuals in a Power BI report which are not used in any visuals within the report

rpt.remove_unnecessary_custom_visuals()

Hide all pages which are used for a tooltip or drillthrough

rpt.hide_tooltip_drillthrough_pages()

 

2 Replies

  • Hi mikova 

    thanks for this fantastic notebook. I got a general question.

    rpt.list_semantic_model_objects(extended=True)

    Why is this list showing me dependencies that are not really in my report? I got a lot of FALSE results in my report and after checking the visuals, I was not able to find an issue or something broken (a missing dependency). 

    Is there any way to programatically clean the visuals of this old/not correct information? 

    thanks!

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thannks for this amazing overview of functions!

    However, I do run into the foloowing issue. Reportwrapper only works with .pbir files, which is not the file type version on app.powerbi.com. Only option I come across is downloading both the file and the notebook locally. Is there a possibility to use reportwrapper while staying in fabric lakehouse environment of app.powerbi.com?

    kind regards, Lidewij