Defining Metrics

Learn how to create and manage business metrics

Last updated: 1/17/2025

Metrics help you track key performance indicators (KPIs) and business health.

What are Metrics?

Metrics in Contextflo are:

  • Computed values based on your data
  • Tracked over time for trend analysis
  • Reusable across dashboards and reports
  • Shareable with your team

Common Metrics

Examples of business metrics:

  • Revenue Metrics: MRR, ARR, ARPU
  • Growth Metrics: User growth rate, churn rate
  • Engagement Metrics: DAU, MAU, retention
  • Sales Metrics: Conversion rate, deal velocity
  • Product Metrics: Feature adoption, usage frequency

Creating a Metric

Step 1: Navigate to Metrics

Click Metrics in the sidebar, then Create New Metric.

Step 2: Define Basic Information

Provide:

  • Name: Descriptive metric name
  • Slug: URL-friendly identifier
  • Description: What this metric measures
  • Category: Group similar metrics

Step 3: Write the Formula

Metrics use SQL to compute values:

Loading code sample...

Step 4: Configure Computation

Set how often to compute:

  • Daily: For high-frequency metrics
  • Weekly: For trend analysis
  • Monthly: For business reporting

Step 5: Test and Save

  1. Click Evaluate to test
  2. Verify the result makes sense
  3. Click Save

Metric Formulas

Simple Count

Loading code sample...

Sum of Values

Loading code sample...

Average

Loading code sample...

Percentage

Loading code sample...

Growth Rate

Loading code sample...

Metric Dependencies

Metrics can reference other metrics:

Loading code sample...

The @metric_slug syntax references other metrics by their slug.

Best Practices

Use Descriptive Names

Good:

  • Monthly Recurring Revenue (MRR)
  • Daily Active Users (DAU)
  • Customer Acquisition Cost (CAC)

Bad:

  • Metric 1
  • Data
  • Count

Include Time Windows

Always specify time ranges:

Loading code sample...

Handle NULL Values

Use NULLIF to avoid division by zero:

Loading code sample...

Document Your Logic

Add comments to complex formulas:

Loading code sample...

Metric Computation

Automatic Computation

Metrics are computed:

  • On schedule (daily, weekly, monthly)
  • When manually triggered
  • When referenced by dashboards

Computation History

View historical values:

  1. Click on a metric
  2. Go to History tab
  3. See trends over time

Manual Computation

Force recomputation:

  1. Open the metric
  2. Click Compute Now
  3. Wait for completion

Metric Validation

Contextflo validates metrics before saving:

  • ✅ SQL syntax check
  • ✅ Table existence verification
  • ✅ Column validation
  • ✅ Permission check

Performance Tips

Optimize Queries

Good:

Loading code sample...

Bad:

Loading code sample...

Use Indexes

Ensure indexes on:

  • Date/timestamp columns
  • Columns in WHERE clauses
  • Foreign keys

Aggregate in Database

Let the database do the work:

Loading code sample...

Metric Categories

Organize metrics into categories:

  • Growth: User growth, revenue growth
  • Engagement: DAU, MAU, session length
  • Revenue: MRR, ARPU, LTV
  • Sales: Conversion rate, pipeline value
  • Operations: System uptime, error rate

Next Steps