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
- Click Evaluate to test
- Verify the result makes sense
- 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:
- Click on a metric
- Go to History tab
- See trends over time
Manual Computation
Force recomputation:
- Open the metric
- Click Compute Now
- 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