CodeRigor

LESSON

Choose an honest chart for the question

Prepare categorical bar data, retain empty channels and expose a zero baseline while preserving negative adjustments.

Choose a visual from the question and units. “How much net value came from each channel?” is a categorical magnitude comparison, so use bars with a zero baseline. “How did daily value change?” is an ordered time-series question, so a line is useful.

The dashboard will contain both. Its bar chart keeps the zero axis visible and lets negative adjustments extend to the other side. Its line chart labels dates and cents-derived currency, with a clearly displayed domain.

Match the encoding to the question
start / 3
Category magnitudes use bar lengths from zero. Ordered daily observations use a time-series line. Both retain labels and numeric tables.
Match the encoding to the question
Category magnitudes use bar lengths from zero. Ordered daily observations use a time-series line. Both retain labels and numeric tables.

Start from channels and LEFT JOIN the already filtered facts. This retains a channel with no activity. COUNT(s.order_id) counts real matched facts, while COUNT(*) would count the outer join’s placeholder row.

Zero activity in a known category is a meaningful value. Missing source coverage is different and should be labeled unavailable. Keep the distinction in both SQL and interface text.

SQL
WITH channels(channel) AS (VALUES('web'),('store')),
selected(order_id,channel,net) AS (VALUES(1,'web',250))
SELECT c.channel,COALESCE(SUM(s.net),0) AS net,COUNT(s.order_id) AS orders
FROM channels AS c LEFT JOIN selected AS s USING(channel)
GROUP BY c.channel ORDER BY net DESC,c.channel;

A bar’s visible length should measure from zero for this report. If values include negatives, place zero between them. Do not clip negative adjustments or replace them with absolute values. Never change query totals to fit a chart.

Avoid a connected line across unordered channel labels: the line suggests intermediate sequence or continuity that the categories do not have. For the real date sequence, retain the calendar and show every covered day, including zero days.

Color reinforces the marks but carries no unique meaning. The dashboard supplies labels, axis units, signed values, chart descriptions and an HTML data table. Keyboard users can operate every filter; a narrow screen gets a readable stacked layout.

One result, two reading paths
start / 3
Charts summarize the same reconciled values available in the numeric table. Labels, sign and ordering remain available without color.
One result, two reading paths
Charts summarize the same reconciled values available in the numeric table. Labels, sign and ordering remain available without color.
SQL
WITH category(net) AS (VALUES(-500),(0),(800))
SELECT MIN(0,MIN(net)) AS domain_min,MAX(0,MAX(net)) AS domain_max,
       SUM(net) AS reconciled_total FROM category;

Return every channel with its honest bar contract. Test a filter with no matching orders and one with negative net value. The chart total must still reconcile to the KPI.

Next we give the time series a real calendar instead of dropping quiet days.

Download the queries, CSV data and offline report →

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Optional overview of what the later Power BI branch adds. The core SQL/browser lab here uses its own original fixtures and requires no Power BI installation.