Skip to main content

Using Parameters

Parameters in Sightfull provide flexibility to dynamically adjust metrics, dashboards, and other analytics features. This page demonstrates how to define metrics with parameters and use them effectively in various scenarios to enhance your data analysis.

Defining Metrics with Parameters

When defining a metric, you can include parameters to make it more dynamic and adaptable to different contexts. Below are examples that demonstrate how different parameter types can be integrated into metric definitions.

Example: Defining a Metric with a Number Parameter for Group Size

Scenario: Define a sales metric that adjusts the group size dynamically based on user input.

Parameter Definition:

- id: group_size
label: Group Size
description: Customizable group size for data segmentation.
type: number
values_type: any
default: 50

Metric Definition:

- name: sales_by_group_size
entity: sales
operation: sum
measure: $sales_amount
filters:
- sql: "$group_size = $parameter.group_size"

Usage in Metric Reference:

$metric__sales_by_group_size.parameter(group_size=40)

This metric allows users to dynamically adjust the group size for sales data analysis by selecting a value for the group_size parameter.

Example: Defining a Metric with Boolean Parameters for Toggle Options

Scenario: Define a revenue metric that includes or excludes tax based on user preference.

Parameter Definition:

- id: include_tax
label: Include Tax
description: Determines whether to include tax in the total calculation.
type: boolean
values_type: any
default: true

Metric Definition:

- name: revenue_calculation
entity: transactions
operation: sum
expression: "$revenue - CASE WHEN $parameter.include_tax THEN $tax_amount ELSE 0 END"
label: Revenue Calculation

Usage in Metric Reference:

$metric__revenue_calculation(include_tax=true)

This metric allows users to toggle whether to include tax in the total revenue calculation.