Skip to content

One row for each thing

By the end of this page you will have chosen what one row of your view is, and checked that no join or total row makes a figure count more than once.

Finish this sentence before you build the view: “One row is one ______.” Good answers are an order line, a visit, a payment, a shipment, or a store in one month. If the sentence needs the word “and” to cover two kinds of rows, the view holds two kinds of things, and each kind belongs in a view of its own.

BInbox adds up every row it reads, so the sentence is also what a count of rows means on a card. A row that stands for an order line makes a count of rows a count of lines, and a count of orders then needs an order id, as What one line is describes.

A figure kept on the order is repeated on each of the order’s lines when the view joins the two. Each line then adds the whole order’s amount.

An amount that exists only at the order, such as shipping, has two safe places. Spread it over the order’s lines in the view, so that the lines add up to it, or build a second view with one row for each order and connect that view as a dataset of its own.

The same holds for a figure kept on a store, a customer or a product, such as a store’s floor area or a customer’s credit limit. A warehouse table cannot take a table beside it yet, so such a figure cannot be added beside the sales (Add a table works with files). Put the names you split by, such as a store’s region or format, into the view, because a name repeated on each row is harmless. Leave the store’s own amount out, because adding it up repeats it once for each sale.

Run one query on the view. The two numbers it returns must be equal when the row is one thing with its own id.

SELECT COUNT(*) AS row_count, COUNT(DISTINCT order_line_id) AS distinct_lines
FROM reporting.sales;

When row_count is the larger number, a join is repeating rows. Look for the table that has more than one row for each of the keys you joined on.

A table that holds a row of subtotals beside the rows they add up, or a “Total” row at the foot, counts everything twice, because BInbox adds each row it reads.

A percent, a ratio or an average cannot be added up. The total of two stores’ margins is not their combined margin, and the average of two averages is wrong unless the stores sold the same amount.

A numeric column that looks like a rate carries a gray ? in the field pane, where you choose how it adds up. Keeping the amounts in the view means you rarely need to.

A view that already sums by month and store cannot be split by product, and it cannot answer a question the finer rows could. Keep the finest rows people will want to filter or split by, and let BInbox add them up. A table of totals is fine when the totals are all there will ever be, such as a budget with one row for each store and month. BInbox then says that its lines are totals already, so it does not count them, as What one line is describes.