---
title: Create a view
project: OpenReports
version: 1.0
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/openreports/1-0/guides/create-view/
updated: 2026-11-19T07:46:43.104Z
---

# Create a view

> Describe the data your reports can use: an SQL query and a list of fields.

A view tells OpenReports which data reports may use. It is a short JSON document with an SQL query and one entry for each column that people can pick. You write it in the **Views** screen.

![The Views screen with one view named Orders](/files/JapUXU8ws61f.webp)

## Create the view

1. Select **Views** (the layers icon) in the bar on the left.
2. Select **Create**. The **View specification** editor opens with an example.
3. Replace the example with your view, then select **SUBMIT**.

The view appears as a card in the **Views** screen. It is ready to use in reports.

## An example

This view reads a table of orders:

```json
{
	"id": "orders",
	"name": "Orders",
	"sql": "SELECT customer, country, product, quantity, total, paid, dtcreated FROM demo_orders",
	"fields": [
		{ "column": "customer", "name": "Customer", "type": "string", "group": true },
		{ "column": "country", "name": "Country", "type": "string", "group": true },
		{ "column": "product", "name": "Product", "type": "string", "group": true },
		{ "column": "quantity", "name": "Quantity", "type": "number" },
		{ "output": "@", "column": "total", "name": "Total", "type": "number", "format": 2 },
		{ "column": "paid", "name": "Paid", "type": "boolean" },
		{ "column": "dtcreated", "name": "Created", "type": "date", "group": true }
	]
}
```

![The View specification editor with the Orders view](/files/JapUXX8xs60f.webp)

- `sql` selects the data. It can join tables, compute columns and use `WHERE`, like any `SELECT`.
- Each entry in `fields` names a column of that query, the name people see (`name`) and its type (`type`): `string`, `number`, `boolean` or `date`.
- `"group": true` lets reports group rows by this field.

Every key is described in [View definition](../../reference/view-definition/).

## Tips

- Run the SQL in `psql` or another client first. If the SQL is wrong, the report shows no useful data.
- The `id` of each view must be unique. Saving a view with the `id` of another view replaces that view.
- People see only the fields you list, even if the query returns more columns.

Next: [Create a report](../create-report/).
