Retail · Power BI
Connecting Power BI to a PostgreSQL retail database with auto-detected relationships
Independent grading: 100/100(verify, opens in a new tab)
Problem
Nura Ibrahim, a stakeholder at Meridian Retail (simulated retailer), needed a visual analysis of a revenue discrepancy. Before any reporting could begin, the Meridian PostgreSQL database had to be connected to Power BI Desktop with all required tables loaded and relationships in place.
What I did
Using Power Query M code, I connected to the PostgreSQL host and loaded all 8 tables from the retail schema using Import mode, which pulls data into the model rather than querying live. Each table was referenced directly via its schema and item name in PostgreSQL.Database(), keeping the M code consistent and easy to audit. Power BI automatically detected 9 relationships across the model; I verified the sessions-to-customers link was set as inactive to prevent ambiguous filter paths that would corrupt downstream aggregations.
Finding
All 8 required tables loaded correctly in Import mode, with 9 relationships detected and the potentially ambiguous sessions-to-customers relationship correctly marked inactive.
Outcome
Nura received a fully connected data model, including flag columns such as is_duplicate and is_first_order, ready for revenue analysis visuals to be built on top of it.
let
Source = PostgreSQL.Database("ep-frosty-glade-ab4k8hyw-pooler.eu-west-2.aws.neon.tech", "meridian_retail"),
retail_categories = Source{[Schema="retail",Item="categories"]}[Data]
in
retail_categoriesThis M code pattern, repeated for each of the 8 tables, targets the correct PostgreSQL host and schema and loads each table by name into the Import mode model.
Next step
A useful next step would be to test whether the inactive sessions-to-customers relationship produces different totals when activated temporarily, to confirm the ambiguity concern is real and not just theoretical for this dataset.
- PostgreSQL connection via Power BI Import mode
- Power Query M code table transformations
- Inactive relationship configuration in Power BI data model