Skip to content

Block 252 of 297

Period Comparison

This period against the last, metric by metric, with absolute and percent change worked out for you.

Puck key
PeriodComparisonBlock
Export
periodComparisonBlock
React component
<PeriodComparison />
Path
components/puck/period-comparison-block.tsx
Dependencies
None
License
MIT

About this block

When to use it, how to write for it, and what to change in the code.

What it's for

A metric-by-metric comparison of this period against a previous one, with the percent change and the absolute difference calculated for you. In a wide card it is a four-column table; in a narrow one the two period columns fold into a line under each metric name, leaving the change column. Values accept {{ source.field }} bindings and are shown as written.

  • Year-over-year monthly results for a board or donor report
  • Before-and-after figures for a program change
  • Quarter-over-quarter service metrics
Writing the content
  • Write both periods in the same units, like $84,250 and $71,900; the block borrows the unit from how the value is written.
  • Rates already in percent, like 41.2%, show their absolute change in percentage points (pts) rather than percent.
  • Set An increase is to Bad for costs, wait times and response times, so a decrease shows as better.
  • This period and Comparison period become column headings; bind them, like {{ report.period }}. Metrics take one to twelve rows.
Accessibility
  • It is a real table with a hidden caption naming both periods, column headers and metric names as row headers (WCAG 1.3.1).
  • Change badges include hidden "Up" or "Down" and "(better)" or "(worse)" text alongside the arrow, so meaning is not carried by green and red alone (WCAG 1.4.1).
  • In the narrow layout, folded values carry hidden text naming each period, and a missing change reads as "Not available".
Customizing the code
  • The narrow-to-wide switch is the @sm container variant on the period columns.
  • Badge tones are emerald, red and neutral classes in the tone constant; minus signs use a true minus character from MINUS.

Editor fields

What content editors see in the P1 sidebar when they select this block.

  • Titletext
  • Heading levelselect
  • Subtitletext
  • This periodtext
  • Comparison periodtext
  • Metricsarray
  • Footnotetext