Stop 03 · SQL for Power BIProjects · 1/1

Build a Reporting View for a Power BI Report

Part of the Power BI Roadmap

In short

In this project you play both roles: database developer and report builder. You write a clean SQL view, point Power BI at it and prove that a good view makes the report almost build itself.

A project writing a SQL view that joins and filters raw sales tables into a tidy, analysis-ready shape, then connecting Power BI to it and building a short report.

The jaadu arranges a neat shop window display of colourful items while a cluttered storeroom of boxes is visible behind a half-open door.

Think of it like this

A shop window arranged in advance

The storeroom is full of boxes, labels and spare parts. A good shopkeeper arranges a tidy window display every morning with just what customers want to see. A reporting view is that window: it hides the messy storeroom tables and shows Power BI a clean, ready arrangement.

Watch it happen

From raw tables to a report

Raw tables
Join
Clean
CREATE VIEW
Power BI

1/5Orders, OrderItems, Products and Customers sit in separate tables with codes and test rows.

The big ideas

What you need to know

Views are saved queries

A view stores the SELECT, not the data. Every time Power BI reads it, the query runs fresh.

Friendly names

Rename columns in the view, like cust_city to City, so the Power BI field list reads well.

A reporting schema

Keeping views in a schema like rpt makes it clear which objects are meant for reports.

Folding still works

Power BI treats a view like a table, so filters added in Power Query still fold back to the server.

See it in code

Walk through the code

sql
1CREATE VIEW rpt.vw_SalesLines AS2SELECT3    o.OrderID,4    o.OrderDate,5    c.City,6    c.State,7    p.ProductName,8    p.Category,9    oi.Quantity,10    oi.UnitPrice,11    oi.Quantity * oi.UnitPrice AS LineAmount12FROM dbo.Orders AS o13INNER JOIN dbo.OrderItems AS oi ON oi.OrderID = o.OrderID14INNER JOIN dbo.Products   AS p  ON p.ProductID = oi.ProductID15LEFT  JOIN dbo.Customers  AS c  ON c.CustomerID = o.CustomerID16WHERE o.Status <> 'Cancelled'17  AND o.IsTest = 0;

1/4The view lives in the rpt schema so everyone knows it is meant for reporting.

A SQL Server reporting view: one clean row per order line, test and cancelled orders removed. Create the rpt schema first with CREATE SCHEMA rpt.

Save yourself the pain

Common mistakes

Oops

Building one giant view with every column from every table just in case.

Do this instead

Include only what the report needs. You can add columns later, but extra ones slow every refresh.

Oops

Putting ORDER BY inside the view.

Do this instead

SQL Server does not allow ORDER BY in a view without TOP, and Power BI ignores row order anyway. Sort in the visuals.

Your mission

Ship the view-backed report

~60 min

Quick check

Why use LEFT JOIN for Customers but INNER JOIN for OrderItems in the view?

Go deeper

  1. 1Use a sample database such as a small retail or Sakila-style dataset.
  2. 2Document every column in the view with a short comment.
  3. 3Compare refresh time against loading the raw tables directly.

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge