Create Filter Expressions

A Filter Expression is a Boolean Studio expression which allows filtering of the Survey Data records you want to get from the Api.

Each expression may consist of the following primitives:

  • Constants

  • Variables

  • Operators

  • Functions

In a filter expression you can use variables from all levels (response, loops, respondent). For loops you need to use the aggregating-functions. Note that aggregating-functions are only supported for loops.

In general, each variable in a Studio expression should be specified with the full path <survey id>.<loop level>:<variable id>[<field code>], but the Public Surveys API allows using simplified variable path without survey id. You can also omit loop level if variable is located on the response level.

Please also consider that each survey has two predefined levels and may also contain several loop levels:

  • respondent - respondent data level

  • response(default) - the root level of the response data

  • l1, l2 …​ - loop levels

Basic request
Get https://<host>/v1/surveys/p1231234/responses/data?
    filterExpression=response:status='complete' HTTP/1.1 (1)
Accept: application/json
Authorization: Bearer <access_token>
1 Only get completed responses from the Api.
Table 1. Expression examples
Expressions Description

response:status = 'complete'
:status = 'complete'

status = 'complete'

Only completed responses
The 2-nd expression is valid because variable status is located on the default level response
The 3-rd expression is invalid - missing ':'

response:interview_start > 2020-07-21T15:09:40
response:date_variable = 2020-07-21 OR
response:date_variable = 2020-07-22

Responses created after the given date

Responses with a date matching one of two values

respondent:noOfMailSent >= 2
:noOfMailSent >= 2

Responses of those respondents who were invited at least twice
The 2-nd expression is invalid - loop level required. Respondent is not default level

VAVG(SCORE(:osatGrid)) > 5

Responses with Average of scores in grid greater than 5
Here osatGrid is a rating grid on the response level

SCORE(:osatGrid.support) > 5

Responses with scored grid field greater than 5
Here osatGrid.support is a field in the rating grid osatGrid

SOME(l1:numInLoop > 10, true, response:)
SOME(:numInLoop > 10, true, response:)
l1:numInLoop > 10

Responses with at least one iteration where numeric variable is greater than 10
Here numInLoop is a numeric variable on loop level l1. The 2-nd parameter is internal aggregating function filter which allows filtering loop records to be aggregated. Value true means that all loop records are aggregated. The 3-rd parameter is the level which the aggregation is performed to.
The 2-nd expression is invalid - loop level required. l1 is not default level
The 3-rd expression is invalid - Aggregating function required

EVERY(l1:numInLoop > 10, true, response:)

Only responses where for each loop iteration numeric variable is greater than 10

SUM(l1:numInLoop, true, response:) > 100

Responses with sum of a numeric variable for all loop iterations is greater than 10

:num1 + :num2

Invalid filter expression - not a Boolean one

BETWEEN(response:responseid, 1, 4)

responseid between the given values

LEN(response:email) = 10
OR
CONTAINS(LOWER(response:email), '@gmail.com')

ISNULL(response:email, '') = ''
OR
TOINT(response:zipcode) = 23322

IIF(response:q1 = 'a', response:text1 : response:text2) = 'some text'

IN(response:cars, 'bmw', 'ford', 'vw')
AND
IN(response:grid_question.field1, 'code1', 'code3', 'code5')

Field is one of the given values

ALL(response:MultiQuestion)

All options selected

ANY(response:MultiQuestion)

Any option selected

VSELECTED(response:MultiQuestion) = 3

Exactly three options selected

VSUM(response:NumericListQuestion) = 456

MONTH(GETDATE()) = 12 AND DAY(GETDATE()) = 24

WEEK(response:BoardingDate) = 23 AND DAY(GETDATE()) = 24

DIFFMONTH(GETDATE(), response:MyDate) = 2

ADDDAY(GETDATE()) > response:MyDate

NOT(response:status='complete')