Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
My goal is to extract a list of tables and M queires for each of them from a Semantic Model/Dataset published on a Fabric Workspace.
I use Fabric Notebooks and Python SemPy library to extract such things as tables, columns, relationships, measures, sources etc. and it works just fine but I have troubles with extracting M Code which is nested in TMSL Code.
Here I found example by Sandeep Pawar where he extracts different atributes from TMSL. I tried to edit his code to extract also M Code but failed as I do not fully understand his Python code.
https://fabric.guru/fabric-semantic-link-and-use-cases
Code:
import json
import pandas as pd
import sempy.fabric as fabric
dataset_name = "Test Dataset for SemPy"
workspace_name = "Fabrics Preview"
def custom_flatten(json_object, dataset_name, table_name=None, table_properties=None, column_name=None, flat_list=None):
if flat_list is None:
flat_list = []
if table_properties is None:
table_properties = {}
if not table_name: # Dataset level
for k, v in json_object.items():
if k == 'model':
table_properties.update({f"dataset_{key}": value for key, value in v.items() if key != 'tables'})
custom_flatten(v, dataset_name, table_properties=table_properties, flat_list=flat_list)
elif k == 'tables': # Table level
for table in v:
custom_flatten(table, dataset_name, table_name=table['name'], table_properties=table_properties, flat_list=flat_list)
elif k != 'name':
table_properties[f"dataset_{k}"] = v
elif not column_name: # Table level
for k, v in json_object.items():
if k == 'columns': # Column level
for column in v:
custom_flatten(column, dataset_name, table_name, table_properties, column_name=column['name'], flat_list=flat_list)
elif k != 'name':
table_properties[f"table_{k}"] = v
else: # Column level
column_properties = {f"column_{k}": v for k, v in json_object.items() if k != 'name'}
row = {'dataset_name': dataset_name, 'table_name': table_name, **table_properties, 'column_name': column_name, **column_properties}
flat_list.append(row)
return flat_list
tmsl_data = json.loads(fabric.get_tmsl(workspace=workspace_name, dataset=dataset_name))
dataset_name = tmsl_data['name']
flat_data = custom_flatten(tmsl_data, dataset_name)
tmsl_df = pd.DataFrame(flat_data)
tmsl_df.head()
Solved! Go to Solution.
Ok, solved it 🙂
I can run in notebook DAX query with INFO.PARTITIONS() function that reads from DMV
Code:
Ok, solved it 🙂
I can run in notebook DAX query with INFO.PARTITIONS() function that reads from DMV
Code:
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
58 | |
30 | |
24 | |
23 | |
20 |
User | Count |
---|---|
54 | |
33 | |
22 | |
20 | |
20 |