> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dqlabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Setup

> Step-by-step guide to creating a Conditional metric in Prizm, covering rule types, select criteria, and threshold configuration.

<script type="application/ld+json">
  {`{
            "@context": "https://schema.org",
            "@type": "TechArticle",
            "headline": "Conditional Metric Setup",
            "description": "Step-by-step guide to creating a Conditional metric in Prizm, covering rule types, select criteria, and threshold configuration.",
            "url": "https://docs.dqlabs.ai/architecture/metrics/conditional/setup",
            "publisher": {
              "@type": "Organization",
              "name": "DQLabs Inc",
              "logo": "https://media.brand.dev/332adc35-5bc4-4d2b-bf78-256aa4a5e414.svg"
            }
            }`}
</script>

## Creating a conditional metric

<Steps>
  <Step title="Add the metric">
    1. Navigate to **Metric** in the top navigation.
    2. Click the **Add** button (⊕).
    3. Enter a **Metric Name**.
    4. Select **Subcategory: Conditional** from the dropdown.
    5. Enter a **Purpose** description.
    6. Click **Create**.

    <Frame>
      <img src="https://mintcdn.com/dqlabs/ZKrDEZVwUfowQ-cY/images/image-58.png?fit=max&auto=format&n=ZKrDEZVwUfowQ-cY&q=85&s=43028875981be44b37eca4041516263d" alt="Image" width="1030" height="1238" data-path="images/image-58.png" />
    </Frame>
  </Step>

  <Step title="Open the configuration view">
    Click the metric name to open its detail page, and provide the following details

    * **Asset** — the table the metric evaluates
    * **Metadata tabs** — Description, Purpose, Rationale
    * **Conditional Metric Configuration** — three tabs: Configuration, Total Records, Failed Rows
    * **Threshold**
    * **Semantic context** and **Owners**

    <Frame>
      <img src="https://mintcdn.com/dqlabs/ZKrDEZVwUfowQ-cY/images/image-60.png?fit=max&auto=format&n=ZKrDEZVwUfowQ-cY&q=85&s=fe348a561caedd0e1f17635010ac1a37" alt="Image" width="1014" height="1230" data-path="images/image-60.png" />
    </Frame>
  </Step>

  <Step title="Set the asset and metadata">
    **Asset:** Select the table or view this metric will evaluate. Use the **AI-assisted asset selection** button to let Prizm suggest an asset based on the metric name and purpose.

    The **Downstream Impact** counter shows how many other assets depend on this asset — useful for understanding blast radius.

    Fill in the metadata tabs as needed:

    | Tab             | Content                                                                                 |
    | --------------- | --------------------------------------------------------------------------------------- |
    | **Description** | What this metric measures. Prizm AI can suggest a description based on the metric name. |
    | **Purpose**     | Business justification — why this metric exists.                                        |
    | **Rationale**   | The reasoning behind the specific rule chosen.                                          |
  </Step>

  <Step title="Configure the condition rules (Configuration tab)">
    The **Configuration** tab is the core of a conditional metric. It has three sub-sections.

    #### Select criteria

    Expand **Select criteria** to scope which rows are evaluated. By default this uses `SELECT *` (all rows). Choose between:

    * **All columns** — evaluate all columns in the asset
    * **Selected columns** — restrict evaluation to specific columns

    Leave Select criteria empty to evaluate every row in the asset.

    #### Condition rules

    Define what "valid" means for each row. Use the logical operators **NOT / AND / OR** to combine multiple rules. Click **+ Add rule** to add a rule or **+ Add group** to create a nested rule group.

    Select a **Rule type** from the toolbar, then click **+ Add rule**. Each rule type exposes different fields:

    <Tabs>
      <Tab title="Row check">
        **Per-row condition on a single column.** Validates that each record's column value meets a specific condition — e.g., `QTY_SOLD Between 10 and 20`.

        1. Click **Row check** in the rule type toolbar.
        2. Click **+ Add rule**.
        3. **Select column** — choose the column to evaluate.
        4. **Select operator** — choose the comparison (e.g., `=`, `!=`, `Between`, `Is Null`, `Is Not Null`).
        5. For range operators (e.g., `Between`), enter a **Start value** and **End value**.
        6. For single-value operators, enter the comparison **Value**.

        <Frame>
          <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/COnditional_Row_Check.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=6f968e04160465d3c7580908f8429f6a" alt="C Onditional Row Check" width="2294" height="1136" data-path="images/COnditional_Row_Check.png" />
        </Frame>
      </Tab>

      <Tab title="Col vs col">
        **Compares one column to another.** Enforces cross-column consistency — e.g., `end_date >= start_date`.

        1. Click **Col vs col** in the rule type toolbar.
        2. Click **+ Add rule**.
        3. **Select column** — choose the first (left-hand) column.
        4. **Select operator** — choose the comparison operator.
        5. A second column picker appears — select the **comparison column**.

        <Frame>
          <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/Conditional_Col_Vs_Col.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=1e3bcdbc7b16b161eff542cc337ad465" alt="Conditional Col Vs Col" width="2278" height="1132" data-path="images/Conditional_Col_Vs_Col.png" />
        </Frame>
      </Tab>

      <Tab title="Aggregate">
        **Set-level assertion — evaluates across all rows.** Enforces dataset-wide constraints — e.g., no duplicate values in a column.

        1. Click **Aggregate** in the rule type toolbar.
        2. Click **+ Add rule**.
        3. **Function** — select the aggregate function from the dropdown (e.g., `No duplicates on`).
        4. **Select columns** — choose one or more columns the function applies to.

        <Frame>
          <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/Conditional_Aggregate.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=9dec3760b31a5df88460e2db3461828b" alt="Conditional Aggregate" width="2282" height="1142" data-path="images/Conditional_Aggregate.png" />
        </Frame>
      </Tab>

      <Tab title="If–then">
        **Conditional logic — condition only fires when the guard clause is true.** Use when a rule should apply only to rows that satisfy a prior condition — e.g., if `order_type = 'express'` then `carrier_tracking_number` is not null.

        1. Click **If–then** in the rule type toolbar.
        2. Click **+ Add rule**.
        3. In the **IF** section — define the guard clause:
           * **Select column** — the guard column.
           * **Select operator** — the guard condition.
        4. In the **THEN** section — define the required outcome:
           * **Select column** — the column that must satisfy the consequence.
           * **Select operator** — the consequence condition.

        <Frame>
          <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/COnditional_If_Then.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=2c41f12706c5af70f58919606904bb36" alt="C Onditional If Then" width="2298" height="1172" data-path="images/COnditional_If_Then.png" />
        </Frame>
      </Tab>

      <Tab title="Expression">
        **Build a WHERE predicate — rows must satisfy this condition.** Use for complex expressions that cannot be captured by the other rule types. The expression builder combines columns, functions, and operators into a custom SQL WHERE clause.

        1. Click **Expression** in the rule type toolbar.
        2. Click **+ Add rule**.
        3. In the **COLUMNS** panel on the left, click a column name to insert it into the expression area.
        4. Switch to the **FUNCTIONS** tab to insert SQL functions.
        5. Use the operator buttons to build the full condition: `AND`, `OR`, `NOT`, `=`, `!=`, `<`, `>`, `<=`, `>=`, `BETWEEN`, `IN`, `IS NULL`, `IS NOT NULL`.
        6. The completed expression becomes the WHERE predicate evaluated row-by-row. Rows satisfying it are counted as valid.

        <Frame>
          <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/Conditional_Expression.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=c56d2ad2c4598398f6ea0d2ac262608e" alt="Conditional Expression" width="2302" height="1312" data-path="images/Conditional_Expression.png" />
        </Frame>
      </Tab>
    </Tabs>

    #### Rule options

    | Option            | Description                                                       |
    | ----------------- | ----------------------------------------------------------------- |
    | **Valid**         | Count only rows that satisfy the rule as valid records            |
    | **Scoring**       | Include this rule in the asset quality score                      |
    | **Weightage%**    | Relative weight of this metric in the overall score (default 100) |
    | **Pass Criteria** | Score percentage above which the rule passes (default `>= 100`)   |
    | **Export**        | Include rule results in data exports                              |

    Click **Validate** to test the rule against current data and preview Valid / Invalid counts. Click **View prepared query** to inspect the underlying SQL Prizm generates.
  </Step>

  <Step title="Define Total Records and Failed Rows queries (optional)">
    The **Total Records** and **Failed Rows** tabs let you override how Prizm counts the denominator and numerator of the score — useful when the default row counts don't reflect your business logic.

    | Tab               | Description                                                                                                                           |
    | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
    | **Total Records** | Custom SQL query that defines what counts as the total record population. Leave empty to use the full row count from Select criteria. |
    | **Failed Rows**   | Custom SQL query that defines which records are considered failed/invalid. Leave empty to use the rows that fail the Condition rules. |

    Both tabs support **Prizm AI suggestions** — click the AI icon to generate an appropriate query based on the metric context.

    <Frame>
      <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/AI_Assit_Query.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=e65183f2a4d09b6e6e36fb482b0a99d1" alt="AI Assit Query" width="2322" height="1200" data-path="images/AI_Assit_Query.png" />
    </Frame>
  </Step>

  <Step title="Set the threshold">
    Choose how Prizm determines when to raise an alert:

    **Automated Threshold** — Prizm learns statistical baselines from historical data and alerts when invalid row counts deviate by a configurable number of standard deviations:

    | Priority     | Deviation range | Default                            |
    | ------------ | --------------- | ---------------------------------- |
    | **Low**      | 0σ – 1σ         | Off — within expected variation    |
    | **Medium**   | 1σ – 2σ         | Off — monitor for drift            |
    | **High**     | 2σ – 3σ         | **On** — investigation recommended |
    | **Critical** | ≥ 3σ            | **On** — immediate action required |

    **Custom Threshold** — Set explicit upper and/or lower bounds on the invalid row count or score to trigger alerts.

    <Frame>
      <img src="https://mintcdn.com/dqlabs/i5TO8rBWx55OpAVC/images/Conditional_Custom_Threshold.png?fit=max&auto=format&n=i5TO8rBWx55OpAVC&q=85&s=2cda89fdf00617eaccdfeead2fb373b7" alt="Conditional Custom Threshold" width="2306" height="570" data-path="images/Conditional_Custom_Threshold.png" />
    </Frame>
  </Step>

  <Step title="Set semantic context and owners">
    Scroll down past the Threshold section to complete:

    * **Semantic context**: Assign Domain, Application, Product, Tag, and Dimension to make the metric discoverable and contextually relevant.
    * **Owners**: Set Business owner, Technical owner, and Steward.
    * **Audience**: Restrict who can view this metric's results.

    Click **Save Changes** when done.
  </Step>
</Steps>
