You can use variables to dynamically change values in your queries. Variables use the syntax ${{variable_name|default_value}} or ${{variable_name|default_value|prefix}} to act as placeholders. By defining variables, you can filter data on a single chart or an entire dashboard without modifying the underlying query statement. This topic describes how to filter an entire dashboard and individual charts.
Filter a dashboard
Filter types
Each chart is based on a query statement. You can add a filter to a dashboard to modify query conditions for all charts simultaneously. This lets you refine the data displayed across the entire dashboard. Simple Log Service (SLS) supports the following filter types:
-
Filter: Filters data based on log field
key:valuepairs. This filter narrows down the results of a query by finding logs that either contain or do not contain a specific key-value pair. For example, to view page views (PVs) for different request methods, you can add a filter with a dynamic list item. -
Variable replacement: Replaces a placeholder in a query statement with a user-selected value. First, you add a variable to your chart's query statement. Then, you create a filter that provides values for that variable. This lets you dynamically change the query without editing it directly. For example, you can use it to view PVs over different time intervals, such as every 10, 60, or 600 seconds.
-
Metric filter: Filters time-series data based on metric labels and values. After you collect metric data, you can add a metric filter to your dashboard. You can specify multiple conditions, which are combined with a logical AND operation.
Standard filter
Variable replacement filter
Metric filter
Filter a chart with variable replacement
You can apply variable replacement to a single chart. SLS adds a filter to the upper-left corner of the chart, allowing you to filter its data independently. The following example shows how to configure a table to display PVs over different time intervals.
1. Configure variable replacement
-
On the chart editing page, configure the time range, Logstore, and a query statement that contains a variable.
The query statement to view page views (PV) at different time intervals is as follows, where
${{date|60}}sets the variabledatewith a default value of 60.* | select __time__ - __time__ % ${{date | 60}} as time, COUNT(*) as pv, avg(request_time) as duration, request_method GROUP BY time, request_method order by time limit 1000
-
Configure the variable replacement settings.
-
On the right side of the chart editing page, select Table as the chart type, and then click .

-
In the Variable replacement dialog box, set Variable key to
dateand Display Name toTime. Then, define the values. For example, create two options with the Display Name valuesminandhourand corresponding variable values of60and3600.
-
-
In the upper-right corner of the page, click OK. Then, click Save. In the Save Dashboard dialog box, click Confirm.
2. Filter the chart
After you save the settings, a filter appears in the upper-left corner of the chart. When you select a value, SLS runs the query with the new value. For example, if you select hour, the executed query is:
(*)| select __time__ - __time__ % 3600 as time, COUNT(*) as pv, avg(request_time) as duration, request_method GROUP BY time, request_method order by time limit 1000

Use variables with interaction events
When you configure an interaction event for a chart, you can set a variable. When you click a value on the chart that triggers the event, the variable automatically updates to that value. This lets you link charts and perform further analysis. For an example, see Configuration examples.

Advanced use of variables with a prefix
When filtering a dashboard or chart, you can use the ${{variable_name|default_value|prefix}} syntax to include a prefix.
-
If no value is selected for the variable, the query uses the default value.
-
If a value is selected, the query combines the prefix and the selected value.
Filter a dashboard by HTTP method (http_method)
Variable format
-
Variable format:
${{method_filter|http_method in ('GET','POST')|http_method =}} -
Query statement:
(*)|select status, count(1) as err_count where ${{method_filter|request_method in ('GET','POST')|request_method =}} and status>=400 group by status-
When no variable value is set: The query calculates the error distribution for GET and POST requests with a status code of 400 or higher. The executed query statement is:
(*)|select status, count(1) as err_count where request_method in ('GET','POST') and status>=400 group by status -
When the variable value is set to
'DELETE': The query analyzes the error status for theDELETEmethod. The executed query is:(*)| select status, count(1) as err_count where request_method ='DELETE' and status>=400 group by status
-
Procedure
-
Configure the chart: On the left side of the page, configure the time range, Logstore, and a query statement that contains the variable. On the right side, select a chart type. Click Apply to preview the chart, and then click OK to save it.

-
Configure the variable filter: In the Filter panel, add selectable values for the
method_filtervariable, as shown in the following figure.
-
Filter the dashboard: Click the filter and select
DELETE. The dashboard updates based on the following query statement:(*)| select status, count(1) as err_count where request_method ='DELETE' and status>=400 group by status
Filter a chart by request_time threshold
Variable format
-
Variable format:
${{slow_query|request_time>50|request_time>}} -
Query statement:
(*)| select request_uri, avg(request_time) as avg_time where ${{slow_query|request_time>50|request_time>}} group by request_uri order by avg_time desc-
When no variable value is set: The query filters for APIs with a request time greater than 50 ms and sorts them by average request time in descending order. The executed query statement is:
(*)| select request_uri, avg(request_time) as avg_time where request_time>50 group by request_uri order by avg_time desc -
When the variable value is set to
1000ms: The query analyzes slow APIs that take longer than 1,000 ms. The executed query is:(*)| select request_uri, avg(request_time) as avg_time where request_time>1000 group by request_uri order by avg_time desc
-
Procedure
-
Configure the chart: On the chart editing page, configure the time range, Logstore, and a query statement that contains the variable.

-
Configure variable replacement: On the right side of the chart editing page, click Variable replacement. In the Variable replacement dialog box, add selectable values for the
slow_queryvariable, as shown in the following figure.
-
Filter the chart: Click the filter in the upper-left corner of the chart. When you select
1000ms, the chart displays statistics using the following query:(*)| select request_uri, avg(request_time) as avg_time where request_time>1000 group by request_uri order by avg_time desc







