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 │ │ │
│ │ ├─────────────────────────────────────┼─────────┼─────────────────────────┼────────────────┼─────────────┤ │