Power BI Integration
The pbix community extension, which reads .pbix files, is not published for DuckDB 2.0.1, the DuckDB version flAPI has embedded since v26.11.23. INSTALL pbix FROM community fails with HTTP 404 (checked for linux_amd64, osx_arm64 and windows_amd64 on 2026-11-25), and because a failing init stops startup, a config that installs it does not start.
It is still published for DuckDB 1.5, so the export below works with a DuckDB 1.5 command-line client, outside flAPI.
A Power BI Desktop file holds a data model: tables, relationships and calculated columns that someone already cleaned and agreed on. Serving those tables as an API lets an app, a scheduled report or an AI agent use the same numbers without rebuilding the model.
What works today: export to Parquet, serve the Parquet
Export the model's tables to Parquet with the DuckDB 1.5 CLI and the pbix extension, then let flAPI serve the files:
#!/usr/bin/env bash
set -euo pipefail
# DuckDB 1.5.x CLI, not flAPI
duckdb -c "
INSTALL pbix FROM community;
LOAD pbix;
COPY (SELECT * FROM pbix_read('models/sales_model.pbix', 'Sales'))
TO 'data/sales.parquet' (FORMAT PARQUET);
COPY (SELECT * FROM pbix_read('models/sales_model.pbix', 'Date'))
TO 'data/dates.parquet' (FORMAT PARQUET);
"
pbix_read(file, table) reads one table of the model; pbix_meta(file, meta_table) reads the model's metadata, for example the list of tables. Run the export whenever the .pbix file is refreshed: from the same job that refreshes it, or from cron.
project-name: powerbi-api
template:
path: ./sqls
connections:
sales:
properties:
path: ./data/sales.parquet
url-path: /sales
request:
- field-name: year
field-in: query
required: false
validators:
- type: int
min: 2000
max: 2100
- field-name: region
field-in: query
required: false
validators:
- type: enum
allowedValues: [North, South, East, West]
template-source: sales.sql
connection: [sales]
SELECT *
FROM read_parquet('{{{ conn.path }}}')
WHERE ({{ params.year }} IS NULL OR Year = {{ params.year }})
{{#params.region}}
AND Region = '{{{ params.region }}}'
{{/params.region}}
ORDER BY Year DESC
The column names are placeholders for your model's. year stays bound because it is outside any section; region is text inside a section, behind an enum validator. No LIMIT: GET endpoints are paginated. A local Parquet file is fast enough to serve live; see Parquet Files.
When pbix is published for DuckDB 2.0.1
flAPI could then read the .pbix file directly, from a cache populate template:
connections:
sales-model:
init: |
INSTALL pbix FROM community;
LOAD pbix;
properties:
pbix_file: /data/models/sales_model.pbix
CREATE OR REPLACE TABLE {{cache.catalog}}.{{cache.schema}}.{{cache.table}} AS
SELECT * FROM pbix_read('{{{ conn.pbix_file }}}', 'Sales')
initruns once at startup and is not a template; the file path belongs inproperties, read as{{{ conn.pbix_file }}}(triple braces: double braces HTML-escape/).conn.*comes from the endpoint's first connection only; a template that needs two models names their paths itself.- Cache it: a
.pbixfile can be hundreds of MB, and reading it on every request is slow.
What a .pbix reader can and cannot do
Works: reading the tables of the model, including calculated columns; joining them like any other tables; filtering, aggregating, and mixing them with other sources.
Does not work:
- DAX measures. There is no DAX engine in DuckDB. Materialise a measure as a calculated column or a table in Power BI, or reimplement it in SQL.
- Write-back. The file is read-only.
- Power BI Service datasets. Only
.pbixfiles, not cloud semantic models. - Live data. The data is as fresh as the last refresh of the file.
Reimplementing a year-over-year measure in SQL, for example:
SELECT cur.Month,
cur.Sales AS current_sales,
prev.Sales AS prior_year_sales,
ROUND((cur.Sales - prev.Sales) / NULLIF(prev.Sales, 0) * 100, 2) AS yoy_growth_pct
FROM monthly_sales cur
LEFT JOIN monthly_sales prev
ON prev.Year = cur.Year - 1 AND prev.Month = cur.Month
(NULLIF matters: in DuckDB 2.0.1, / by zero returns inf (or -inf), which would show up as a growth figure; only integer division // and modulo % by zero raise an error. With NULLIF a month without prior-year sales gives NULL.)
Best practices
- Keep the
.pbixfile and its exports out of the web root and readable only by the flAPI service user. - Automate the refresh chain: refresh the
.pbixfile, export, done. flAPI re-reads a Parquet file on every live request. - Write files atomically: export to a temporary name, then rename, so a request never reads half a file.
- Require authentication on endpoints that serve business numbers; see Authentication.
Migration path
- Today: export
.pbixtables to Parquet, serve the Parquet. - Later: move the model's source tables to a warehouse or database and serve them from there, with a cache in front. The endpoints and validators stay the same.
Next steps
- Parquet Files: serving the exported files
- Caching Setup: refresh modes and schedules
- Connections Overview: which sources work with DuckDB 2.0.1