Query Patterns

Goal: Reusable patterns for common industrial data queries.


What is a Pattern?

A pattern is a query template that solves a common industrial problem:

ElementDescription
ProblemThe business question being answered
Query structureKQL template with placeholders
Customization pointsWhat you'll change for your use case
Example outputWhat the results look like

Patterns aren't copy-paste solutions. They're starting points. Azi helps you adapt them to your specific data structure and business rules.


Time-Series Aggregation

Problem: "What's the average temperature over the last 8 hours?"

Pattern

{TableName}
| where Timestamp > ago({TimeRange})
| summarize
    Avg = avg({MetricColumn}),
    Min = min({MetricColumn}),
    Max = max({MetricColumn})
    by bin(Timestamp, {BinSize})
| order by Timestamp asc

Customization Points

PlaceholderExample
{TableName}SensorReadings
{TimeRange}8h, 1d, 7d
{MetricColumn}Temperature, Pressure
{BinSize}1h, 15m, 5m

Ask Azi


Threshold Alerting

Problem: "Show me all readings that exceeded the threshold."

Pattern

{TableName}
| where Timestamp > ago({TimeRange})
| where {MetricColumn} > {Threshold}
| project Timestamp, DeviceId, {MetricColumn},
          Deviation = {MetricColumn} - {Threshold}
| order by Deviation desc

Customization Points

PlaceholderExample
{Threshold}25.0 (temperature), 150 (pressure)
{MetricColumn}Temperature, Vibration

Variations

Below threshold:

| where {MetricColumn} < {LowerThreshold}

Outside range:

| where {MetricColumn} < {LowerThreshold} or {MetricColumn} > {UpperThreshold}

Ask Azi


Device Comparison

Problem: "Compare performance across multiple devices."

Pattern

{TableName}
| where Timestamp > ago({TimeRange})
| where DeviceId in ({DeviceList})
| summarize
    AvgValue = avg({MetricColumn}),
    ReadingCount = count(),
    LastReading = max(Timestamp)
    by DeviceId
| order by AvgValue desc

Customization Points

PlaceholderExample
{DeviceList}"T-01", "T-02", "T-03"
{MetricColumn}CycleTime, Output

Example Output

DeviceIdAvgValueReadingCountLastReading
T-0122.41,2472024-01-15 14:32:00
T-0223.11,1982024-01-15 14:31:45
T-0321.81,2562024-01-15 14:32:15

Ask Azi


Historical Trend Analysis

Problem: "How has this metric changed over time?"

Pattern

{TableName}
| where Timestamp > ago({TimeRange})
| summarize DailyAvg = avg({MetricColumn}) by bin(Timestamp, 1d)
| extend MovingAvg = row_window_session(DailyAvg, Timestamp, 7d, 1d)
| project Timestamp, DailyAvg,
          TrendDirection = iff(DailyAvg > prev(DailyAvg), "Up", "Down")

Customization Points

PlaceholderExample
{TimeRange}30d, 90d
{MetricColumn}OEE, FirstPassYield

Variations

Week-over-week comparison:

| extend WeekNumber = week_of_year(Timestamp)
| summarize WeeklyTotal = sum({MetricColumn}) by WeekNumber
| extend PreviousWeek = prev(WeeklyTotal)
| extend Change = (WeeklyTotal - PreviousWeek) / PreviousWeek * 100

OEE Calculation

Problem: "Calculate Overall Equipment Effectiveness."

Pattern

let PlannedTime = {PlannedProductionTime};
let IdealCycleTime = {IdealCycleSeconds};
{ProductionTable}
| where Timestamp > ago({TimeRange})
| summarize
    RunTime = sum(iff(Status == "Running", Duration, 0)),
    TotalUnits = sum(Units),
    GoodUnits = sum(iff(Quality == "Pass", Units, 0))
| extend Availability = RunTime / PlannedTime
| extend Performance = (TotalUnits * IdealCycleTime) / RunTime
| extend Quality = GoodUnits / TotalUnits
| extend OEE = Availability * Performance * Quality * 100
| project
    Availability = round(Availability * 100, 1),
    Performance = round(Performance * 100, 1),
    Quality = round(Quality * 100, 1),
    OEE = round(OEE, 1)

Customization Points

PlaceholderExample
{PlannedProductionTime}28800 (8 hours in seconds)
{IdealCycleSeconds}60 (1 minute per unit)
{ProductionTable}ProductionData
Thinking Tip:

OEE components vary by industry. Adjust the calculation logic to match your standard.


Downtime Pareto

Problem: "What are the top causes of downtime?"

Pattern

{DowntimeTable}
| where Timestamp > ago({TimeRange})
| summarize
    TotalMinutes = sum(DurationMinutes),
    Occurrences = count()
    by Cause
| extend TotalDowntime = toscalar(
    {DowntimeTable}
    | where Timestamp > ago({TimeRange})
    | summarize sum(DurationMinutes))
| extend Percentage = round(TotalMinutes / TotalDowntime * 100, 1)
| top 10 by TotalMinutes desc
| project Cause, TotalMinutes, Occurrences, Percentage

Example Output

CauseTotalMinutesOccurrencesPercentage
Material shortage2451228.4%
Tool change1893421.9%
Quality hold156818.1%

Batch Traceability

Problem: "Trace all steps for a specific batch or lot."

Pattern

{ProductionTable}
| where LotNumber == "{LotId}"
| join kind=leftouter {QualityTable} on LotNumber
| project
    Timestamp,
    Step,
    Station,
    Operator,
    ProcessParameters = pack_all(),
    QualityResult
| order by Timestamp asc

Customization Points

PlaceholderExample
{LotId}"LOT-2024-001234"
{ProductionTable}BatchOperations
{QualityTable}QualityInspections

Batch traceability queries are critical for compliance. Every execution is logged, creating the audit trail regulators require.


Energy Cost Allocation

Problem: "Allocate energy costs to production lines."

Pattern

{EnergyTable}
| where Timestamp > ago({TimeRange})
| summarize TotalkWh = sum(kWh) by Line
| extend CostPerKwh = {RatePerKwh}
| extend TotalCost = TotalkWh * CostPerKwh
| extend TotalEnergy = toscalar(
    {EnergyTable}
    | where Timestamp > ago({TimeRange})
    | summarize sum(kWh))
| extend CostShare = round(TotalkWh / TotalEnergy * 100, 1)
| project Line, TotalkWh, TotalCost, CostShare
| order by TotalCost desc

Customization Points

PlaceholderExample
{RatePerKwh}0.12 ($/kWh)
{EnergyTable}EnergyReadings

Using Patterns with Azi

Patterns work best when you describe what you need:

  1. Start with the pattern type: "I need a threshold alerting query..."
  2. Specify your data: "...for temperature readings from cleanroom sensors..."
  3. Add constraints: "...that shows violations above 23°C in the last 8 hours."

Pattern Library by Journey

PatternPharmaEnergyManufacturing
Time-series aggregation✓✓✓
Threshold alerting✓✓✓
Device comparison✓✓✓
Historical trend✓✓✓
OEE calculation--✓
Downtime pareto--✓
Batch traceability✓-✓
Energy cost allocation-✓✓

Next Steps

If you want to...Go to...
Try pharma patternsPharma Journey →
Try energy patternsEnergy Journey →
Try manufacturing patternsManufacturing Journey →
Learn query basicsQuery Guide →
On this page