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
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. |
Expressions | Description |
---|---|
response:status = 'complete' status = 'complete' |
Only completed responses |
response:interview_start > 2020-07-21T15:09:40 |
Responses created after the given date |
respondent:noOfMailSent >= 2 |
Responses of those respondents who were invited at least twice |
VAVG(SCORE(:osatGrid)) > 5 |
Responses with Average of scores in grid greater than 5 |
SCORE(:osatGrid.support) > 5 |
Responses with scored grid field greater than 5 |
SOME(l1:numInLoop > 10, true, response:) |
Responses with at least one iteration where numeric variable is greater than 10 |
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 |
|
ISNULL(response:email, '') = '' |
|
IIF(response:q1 = 'a', response:text1 : response:text2) = 'some text' |
|
IN(response:cars, 'bmw', 'ford', 'vw') |
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') |