Overview

The Analytics API provides statistical analysis queries for KPI data. It supports single-KPI trend analysis with anomaly detection, multi-KPI comparison with normalization, Pareto analysis for root cause investigation, and cross-board KPI benchmarking.

All queries are scoped to the caller’s organization via organizationId from the authenticated session.

Get KPI Trend

Retrieve trend analysis data for a single KPI, including raw values, moving average, statistical summary, anomaly markers, and a linear regression trendline.

GET /api/trpc/analytics.getKpiTrend?input={"json":{"kpiDefinitionId":"kpi_01HXK5...","timeRange":"30d"}}

Request Parameters:

ParameterTypeRequiredDescription
kpiDefinitionIdstringYesKPI definition ID to analyze
startDatestringNoStart date (ISO 8601). Overrides timeRange if both startDate and endDate are provided
endDatestringNoEnd date (ISO 8601)
timeRangestringNoShorthand: 7d, 30d, 90d, 1y (default: 30d)
windowSizenumberNoMoving average window size, 2-30 (default: 5)

Response:

{
  "result": {
    "data": {
      "json": {
        "kpiDefinitionId": "kpi_01HXK5...",
        "kpiName": "On-Time Delivery Rate",
        "values": [
          {
            "id": "val_01HXK5...",
            "date": "2026-03-01",
            "value": 94.2,
            "movingAvg": 93.8,
            "isAnomaly": false
          },
          {
            "id": "val_01HXK6...",
            "date": "2026-03-08",
            "value": 72.1,
            "movingAvg": 89.4,
            "isAnomaly": true
          },
          {
            "id": "val_01HXK7...",
            "date": "2026-03-15",
            "value": 96.5,
            "movingAvg": 91.2,
            "isAnomaly": false
          }
        ],
        "stats": {
          "mean": 87.6,
          "stdDev": 10.4,
          "p10": 72.1,
          "p50": 94.2,
          "p90": 96.5,
          "count": 3
        },
        "trendline": {
          "slope": 1.15,
          "intercept": 84.3,
          "r2": 0.12
        },
        "anomalies": [
          { "index": 1, "value": 72.1, "deviation": -2.3 }
        ]
      }
    }
  }
}

Response Fields

FieldTypeDescription
valuesarrayTime-series data points with date, value, moving average, and anomaly flag
stats.meannumberArithmetic mean of all values
stats.stdDevnumberStandard deviation
stats.p10number10th percentile
stats.p50number50th percentile (median)
stats.p90number90th percentile
stats.countnumberTotal number of data points
trendline.slopenumberLinear regression slope (positive = improving for higher-is-better)
trendline.interceptnumberY-intercept of the regression line
trendline.r2numberCoefficient of determination (0-1, higher = better fit)
anomaliesarrayData points deviating more than 2 standard deviations from the mean

Get Pareto Data

Perform Pareto analysis on a board column, ranking categories by frequency with cumulative percentages. Identifies the “vital few” categories that account for 80% of occurrences.

GET /api/trpc/analytics.getParetoData?input={"json":{"boardId":"brd_01HXK5...","columnId":"col_01HXK5...","timeRange":"90d"}}

Request Parameters:

ParameterTypeRequiredDescription
boardIdstringYesBoard to analyze
columnIdstringYesColumn whose values to count and rank
timeRangestringNoFilter items by creation date: 7d, 30d, 90d, 1y
groupBystringNoSecondary grouping column
categoryColumnIdstringNoSecondary column to filter by
categoryFilterValuestringNoValue in the category column to filter on
teamFilterstringNoFilter by assignee user ID

Response:

{
  "result": {
    "data": {
      "json": {
        "categories": [
          {
            "category": "Equipment fault",
            "frequency": 45,
            "percentage": 36.0,
            "cumulativePercentage": 36.0
          },
          {
            "category": "Material defect",
            "frequency": 30,
            "percentage": 24.0,
            "cumulativePercentage": 60.0
          },
          {
            "category": "Operator error",
            "frequency": 20,
            "percentage": 16.0,
            "cumulativePercentage": 76.0
          },
          {
            "category": "Process drift",
            "frequency": 12,
            "percentage": 9.6,
            "cumulativePercentage": 85.6
          }
        ],
        "total": 125,
        "thresholdIndex": 3,
        "vitalFewCount": 4
      }
    }
  }
}

Response Fields

FieldTypeDescription
categoriesarrayCategories ranked by frequency (descending)
categories[].categorystringCategory label from the column value
categories[].frequencynumberNumber of items with this value
categories[].percentagenumberPercentage of total (rounded to 2 decimals)
categories[].cumulativePercentagenumberRunning cumulative percentage
totalnumberTotal count across all categories
thresholdIndexnumberIndex of the first category where cumulative % reaches 80%
vitalFewCountnumberNumber of categories that account for 80% of occurrences

Results are bounded to 10,000 items per query to prevent performance issues on large boards. Use timeRange or teamFilter to narrow the dataset if needed.

Get Cross-Board KPI Comparison

Compare a named KPI across multiple boards within the organization. Returns per-board summaries with latest value, trend, mean, and status, plus an organization-wide benchmark.

GET /api/trpc/analytics.getCrossBoardKpiComparison?input={"json":{"kpiName":"OEE","timeRange":"30d"}}

Request Parameters:

ParameterTypeRequiredDescription
kpiNamestringYesKPI name to compare across boards (case-insensitive match)
boardIdsstring[]NoRestrict comparison to specific board IDs
timeRangestringNoTime window: 7d, 30d, 90d, 1y (default: 30d)

Response:

{
  "result": {
    "data": {
      "json": {
        "kpiName": "OEE",
        "boards": [
          {
            "boardId": "brd_01HXK5...",
            "boardName": "Production Line 1",
            "workspaceName": "Manufacturing",
            "latestValue": 92.1,
            "mean": 89.5,
            "stdDev": 3.2,
            "trend": {
              "slope": 0.8,
              "direction": "improving"
            },
            "status": "green",
            "unit": "%",
            "dataPoints": 12
          },
          {
            "boardId": "brd_01HXK6...",
            "boardName": "Production Line 2",
            "workspaceName": "Manufacturing",
            "latestValue": 84.7,
            "mean": 82.3,
            "stdDev": 5.1,
            "trend": {
              "slope": -0.3,
              "direction": "declining"
            },
            "status": "amber",
            "unit": "%",
            "dataPoints": 12
          }
        ],
        "benchmark": 88.4,
        "rankings": [
          { "boardId": "brd_01HXK5...", "boardName": "Production Line 1", "value": 92.1, "rank": 1 },
          { "boardId": "brd_01HXK6...", "boardName": "Production Line 2", "value": 84.7, "rank": 2 }
        ]
      }
    }
  }
}

Response Fields

FieldTypeDescription
kpiNamestringThe KPI name that was searched for
boardsarrayPer-board comparison data
boards[].latestValuenumberMost recent KPI value
boards[].meannumberAverage value over the time range
boards[].stdDevnumberStandard deviation over the time range
boards[].trendobjectLinear regression slope and direction
boards[].statusstringCurrent traffic-light status: green, amber, red
benchmarknumberOrganization-wide average of latest values across all boards
rankingsarrayBoards ranked by latest value (direction-aware: highest first for higher-is-better)

The KPI name matching is case-insensitive. “OEE”, “Oee”, and “oee” all match the same KPI definitions across boards.

The organizationId is always taken from the authenticated session context, never from client input. This prevents cross-tenant data leakage in the comparison results.