This project provides a notebook that automatically extracts the semantic model from a Power BI report (exported as a JSON file), translates DAX measures and calculated columns to Databricks SQL or PySpark, and generates materialized views in Unity Catalog if desired.
- Extracts tables, columns, measures, calculated columns, hierarchies, and relationships from a Power BI semantic model JSON
- Translates DAX to Databricks SQL for most aggregation, logical, time intelligence, and text functions
- Falls back to PySpark for unsupported or complex DAX logic
- Optionally materializes metrics and dimensions as Databricks SQL views
- Outputs a Databricks-importable notebook
The notebook currently maps the following DAX functions to Databricks SQL or PySpark equivalents:
Aggregation Functions (SQL):
SUM→SUM()AVERAGE→AVG()COUNT→COUNT()DISTINCTCOUNT→COUNT(DISTINCT ...)MIN→MIN()MAX→MAX()
Logical Functions (SQL):
IF→CASE WHEN ... THEN ... ELSE ... ENDAND→(... AND ...)OR→(... OR ...)NOT→NOT (...)
Date Functions (SQL):
YEAR→EXTRACT(YEAR FROM ...)MONTH→EXTRACT(MONTH FROM ...)DAY→EXTRACT(DAY FROM ...)QUARTER→EXTRACT(QUARTER FROM ...)
Text Functions (SQL):
CONCATENATE→CONCAT(..., ...)LEFT→SUBSTRING(..., 1, ...)RIGHT→SUBSTRING(..., -...)LEN→LENGTH(...)
Filter Context Functions (SQL):
CALCULATE→... FILTER BY ...FILTER→... WHERE ...
Time Intelligence Functions (SQL):
SAMEPERIODLASTYEAR→DATE_SUB(..., INTERVAL 1 YEAR)DATEADD→DATE_ADD(..., INTERVAL ... ...)DATEDIFF→DATEDIFF(..., ..., ...)
Relationship Functions:
RELATED→ column referenceLOOKUPVALUE→ comment for manual implementation
Other:
- Table[Column] references are mapped to
table.column - Simple
VAR ... RETURN ...blocks are commented for manual review
PySpark Fallback:
- If a DAX function or pattern is not supported in SQL, a comment is inserted in the generated notebook indicating that PySpark implementation is required.
- Examples:
GENERATE,SUMMARIZE,ADDCOLUMNS,SELECTCOLUMNS,UNION,INTERSECT,EXCEPT,EARLIER,PATH,PATHITEMand other advanced DAX patterns.
- Open your report in Power BI Desktop.
- Go to
File→Export→Power BI template(.pbit). - Rename the exported
.pbitfile to.zipand extract it. - Inside the extracted folder, locate the
DataModelSchemaorDataModelJSON file (usually namedDataModelSchemaorDataModel). - Place this JSON file in your working directory and set the
PBI_JSON_PATHvariable in the notebook to its filename.
-
Install the required Python packages:
pip install pandas nbformat
-
Open the notebook
semantic_generator_v11_beastmode_ULTRA_FULL.ipynbin VS Code or Databricks. -
Set the
PBI_JSON_PATHvariable in the configuration cell to the name of your exported JSON file. -
Run all cells. The notebook will generate a new Databricks notebook with SQL and PySpark code for your semantic layer.
- The generated notebook will contain Databricks SQL code to create views for each table, including all columns, calculated columns, and measures.
- If a DAX expression cannot be translated to SQL, a PySpark code comment will be included for manual implementation.
MIT License