Skip to main content

Dagster & Power BI (Component)

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.

info

PowerBIWorkspaceComponent is a state-backed component, which fetches and caches Power BI workspace metadata. For information on managing component state, see Configuring state-backed components.

Step 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

Step 2: Scaffold a Power BI component definition​

Now that you have a Dagster project, you can scaffold a Power BI component definition:

dg scaffold defs dagster_powerbi.PowerBIWorkspaceComponent powerbi_ingest
Creating defs at /.../my-project/src/my_project/defs/powerbi_ingest.

The dg scaffold defs call will generate a defs.yaml file:

tree my_project/defs
my_project/defs
├── __init__.py
└── powerbi_ingest
└── defs.yaml

2 directories, 2 files

Step 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.

my_project/defs/powerbi_ingest/defs.yaml
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 │ │ │
│ │ └─────────────────────────────────────┴─────────┴─────────────────────────┴────────────────┴─────────────┘ │
└─────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Step 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.

my_project/defs/powerbi_ingest/defs.yaml
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:

my_project/defs/powerbi_ingest/defs.yaml
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 │ │
│ │ │ │ semantic_model │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────┤ │
│ │ │ semantic_model/Sales_Data_Model │ powerbi │ True │ │
│ │ │ │ semantic_model │ │ │
│ │ └─────────────────────────────────────┴────────────────┴───────────────┘ │
└─────────┴──────────────────────────────────────────────────────────────────────────┘

Step 5: Customize Power BI asset metadata​

You can customize the metadata and grouping of Power BI assets using the translation key:

my_project/defs/powerbi_ingest/defs.yaml
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 }}"
translation:
group_name: powerbi_data
description: "PowerBI {{ data.content_type.value }}: {{ data.properties.name }}"
dg list defs
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Section ┃ Definitions ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Assets │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓ │
│ │ ┃ Key ┃ Group ┃ Deps ┃ Kinds ┃ Description ┃ │
│ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩ │
│ │ │ dashboard/Marketing_Dashboard │ powerbi_data │ report/Marketi… │ dashboard │ PowerBI │ │
│ │ │ │ │ │ powerbi │ dashboard: │ │
│ │ │ │ │ │ │ Marketing │ │
│ │ │ │ │ │ │ Dashboard │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ dashboard/Sales_Dashboard │ powerbi_data │ report/Sales_R… │ dashboard │ PowerBI │ │
│ │ │ │ │ │ powerbi │ dashboard: │ │
│ │ │ │ │ │ │ Sales │ │
│ │ │ │ │ │ │ Dashboard │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ marketing │ default │ │ │ │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ report/Marketing_Report │ powerbi_data │ semantic_model… │ powerbi │ PowerBI │ │
│ │ │ │ │ │ report │ report: │ │
│ │ │ │ │ │ │ Marketing │ │
│ │ │ │ │ │ │ Report │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ report/Sales_Report │ powerbi_data │ semantic_model… │ powerbi │ PowerBI │ │
│ │ │ │ │ │ report │ report: Sales │ │
│ │ │ │ │ │ │ Report │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ sales │ default │ │ │ │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ semantic_model/Marketing_Data_Model │ powerbi_data │ marketing │ powerbi │ PowerBI │ │
│ │ │ │ │ │ semantic_model │ semantic_mode… │ │
│ │ │ │ │ │ │ Marketing Data │ │
│ │ │ │ │ │ │ Model │ │
│ │ ├─────────────────────────────────────┼──────────────┼─────────────────┼────────────────┼────────────────┤ │
│ │ │ semantic_model/Sales_Data_Model │ powerbi_data │ sales │ powerbi │ PowerBI │ │
│ │ │ │ │ │ semantic_model │ semantic_mode… │ │
│ │ │ │ │ │ │ Sales Data │ │
│ │ │ │ │ │ │ Model │ │
│ │ └─────────────────────────────────────┴──────────────┴─────────────────┴────────────────┴────────────────┘ │
└─────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Customize specific data types​

You may also specify distinct translation behavior for specific data types. For example, you can add a tag to all semantic models:

my_project/defs/powerbi_ingest/defs.yaml
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
translation:
for_semantic_model:
tags:
is_semantic_model: "true"
dg list defs --columns name,kinds,tags
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Section ┃ Definitions ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ Assets │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │
│ │ ┃ Key ┃ Kinds ┃ Tags ┃ │
│ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │
│ │ │ dashboard/Marketing_Dashboard │ dashboard │ "dagster-powerbi/asset_type"="dashboard" │ │
│ │ │ │ powerbi │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ dashboard/Sales_Dashboard │ dashboard │ "dagster-powerbi/asset_type"="dashboard" │ │
│ │ │ │ powerbi │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ marketing │ │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ report/Marketing_Report │ powerbi │ "dagster-powerbi/asset_type"="report" │ │
│ │ │ │ report │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ report/Sales_Report │ powerbi │ "dagster-powerbi/asset_type"="report" │ │
│ │ │ │ report │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ sales │ │ │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ semantic_model/Marketing_Data_Model │ powerbi │ "dagster-powerbi/asset_type"="semantic_model" │ │
│ │ │ │ semantic_model │ "is_semantic_model"="true" │ │
│ │ ├─────────────────────────────────────┼────────────────┼───────────────────────────────────────────────┤ │
│ │ │ semantic_model/Sales_Data_Model │ powerbi │ "dagster-powerbi/asset_type"="semantic_model" │ │
│ │ │ │ semantic_model │ "is_semantic_model"="true" │ │
│ │ └─────────────────────────────────────┴────────────────┴───────────────────────────────────────────────┘ │
└─────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────┘