Dagster & Power BI with components
The dagster-powerbi library provides a PowerBIWorkspaceComponent
which can be used to easily represent Power BI dashboards, reports, semantic models, and data sources as assets in Dagster.
1. Prepare a Dagster project
To begin, you'll need a Dagster project. You can use an existing components-ready project or create a new one:
uvx create-dagster project my-project && cd my-project/src
Activate the project virtual environment:
source ../.venv/bin/activate
Finally, add the dagster-powerbi
library to the project:
uv add dagster-powerbi
2. Scaffold a Power BI component
Now that you have a Dagster project, you can scaffold a Power BI component:
dg scaffold defs dagster_powerbi.PowerBIWorkspaceComponent powerbi_ingest
Creating defs at /.../my-project/src/my_project/defs/powerbi_ingest.
The scaffold call will generate a defs.yaml
file:
tree my_project/defs
my_project/defs
├── __init__.py
└── powerbi_ingest
└── defs.yaml
2 directories, 2 files
3. Configure your Power BI workspace
Update the defs.yaml
file with your workspace ID. You will also need to provide either an API access token or service principal credentials. For more information on how to create a service principal, see Embed Power BI content with service principal and an application secret in the Power BI documentation.
type: dagster_powerbi.PowerBIWorkspaceComponent
attributes:
workspace:
workspace_id: "{{ env.POWERBI_WORKSPACE_ID }}"
credentials:
client_id: "{{ env.POWERBI_CLIENT_ID }}"
client_secret: "{{ env.POWERBI_CLIENT_SECRET }}"
tenant_id: "{{ env.POWERBI_TENANT_ID }}"
# Alternatively, you can use an API access token
# credentials:
# token: "{{ env.POWERBI_API_TOKEN }}"
dg list defs
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Section ┃ Definitions ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Assets │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓ │
│ │ ┃ Key ┃ Group ┃ Deps ┃ Kinds ┃ Description ┃ │
│ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩ │
│ │ │ dashboard/Marketing_Dashboard │ default │ report/Marketing_Report │ dashboard │ │ │
│ │ │ │ │ │ powerbi │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ dashboard/Sales_Dashboard │ default │ report/Sales_Report │ dashboard │ │ │
│ │ │ │ │ │ powerbi │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ marketing │ default │ │ │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ report/Marketing_Report │ default │ semantic_model/Marketi… │ powerbi │ │ │
│ │ │ │ │ │ report │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ report/Sales_Report │ default │ semantic_model/Sales_D… │ powerbi │ │ │
│ │ │ │ │ │ report │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ sales │ default │ │ │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ semantic_model/Marketing_Data_Model │ default │ marketing │ powerbi │ │ │
│ │ │ │ │ │ semantic model │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │
│ │ │ semantic_model/Sales_Data_Model │ default │ sales │ powerbi │ │ │
│ │ │ │ │ │ semantic model │ │ │
│ │ └─────────────────────────────────────┴─────────┴─────────────────────────┴────────────────┴─────────────┘ │
└─────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
4. Enable semantic model refresh
You can enable refreshing semantic models by adding the enable_semantic_model_refresh
key. To enable refresh for all semantic models, set the value to True
.
type: dagster_powerbi.PowerBIWorkspaceComponent
attributes:
workspace:
workspace_id: "{{ env.POWERBI_WORKSPACE_ID }}"
credentials:
client_id: "{{ env.POWERBI_CLIENT_ID }}"
client_secret: "{{ env.POWERBI_CLIENT_SECRET }}"
tenant_id: "{{ env.POWERBI_TENANT_ID }}"
enable_semantic_model_refresh: True
dg list defs --assets 'key:semantic_model*' --columns name,kinds,is_executable
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Section ┃ Definitions ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Assets │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ │
│ │ ┃ Key ┃ Kinds ┃ Is executable ┃ │
│ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │
│ │ │ semantic_model/Marketing_Data_Model │ powerbi │ True │ │
│ │ │ │ semantic model │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────┤ │
│ │ │ semantic_model/Sales_Data_Model │ powerbi │ True │ │
│ │ │ │ semantic model │ │ │
│ │ └─────────────────────────────────────┴────────────────┴───────────────┘ │
└─────────┴──────────────────────────────────────────────────────────────────────────┘
To enable refreshing specific semantic models, set the value to a list of semantic model names:
type: dagster_powerbi.PowerBIWorkspaceComponent
attributes:
workspace:
workspace_id: "{{ env.POWERBI_WORKSPACE_ID }}"
credentials:
client_id: "{{ env.POWERBI_CLIENT_ID }}"
client_secret: "{{ env.POWERBI_CLIENT_SECRET }}"
tenant_id: "{{ env.POWERBI_TENANT_ID }}"
enable_semantic_model_refresh:
- Sales Data Model
dg list defs --assets 'key:semantic_model*' --columns name,kinds,is_executable
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Section ┃ Definitions ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Assets │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ │
│ │ ┃ Key ┃ Kinds ┃ Is executable ┃ │
│ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │
│ │ │ semantic_model/Marketing_Data_Model │ powerbi │ False │ │