x

Main chapters

  1. LimeSurvey Cloud vs LimeSurvey CE
  2. LimeSurvey Cloud - Quick start guide
  3. LimeSurvey CE - Installation
  4. How to design a good survey (Guide)
  5. Getting started
  6. LimeSurvey configuration
  7. Introduction - Surveys
  8. View survey settings
  9. View survey menu
  10. View survey structure
  11. Introduction - Questions
  12. Introduction - Question Groups
  13. Introduction - Surveys - Management
  14. Survey toolbar options
  15. Multilingual survey
  16. Quick start guide - ExpressionScript
  17. Advanced features
  18. General FAQ
  19. Troubleshooting
  20. Workarounds
  21. License
  22. Version change log
  23. Plugins - Advanced
 Actions

StatFunctions plugin

From LimeSurvey Manual

 Hint: This feature is available starting in version 4.1.0


Usage

Functions for the Expression Script engine to count statistical data:

  • statCount(QuestionCode.sgqa[, submitted = 1][, self = true]): counts the number of responses that have already answered (submitted) the question identified by QuestionCode. For example, you can count the number of submitted (completed) responses to the survey with statCount('id').
  • statCountIf(QuestionCode.sgqa, value[, submitted = 1][, self = true]): counts the number of responses where the answer to question QuestionCode equals value. The comparison uses Yii's compare; you can prefix value with an operator such as <, >, >=, <=, or <>.

An example showing both functions in use can be found in the test directory: survey_archive_statCountFunctionsTest.

This plugin relies on the ExpressionManagerStart event, and adds these two functions to it. Neither function has a JavaScript equivalent, so the calculation is only performed when the respondent moves to the next page.

Expression Script does not have true and false as reserved words, so these strings are interpreted as variable names rather than as booleans. For the submitted and self parameters, use 1, 0, or the result of an expression instead — keep in mind that the string "false" evaluates to true in a boolean context.

  Before using these functions, the plugin must be activated in Plugin Manager.


Example

  • Count the number of submitted responses: {statCount("id")}
  • Count the number of responses, submitted or not: {statCount("id", 0)}
  • Number of responses where the respondent stopped on page 1: {statCountIf("lastpage", 1, 0)}
  • Number of submitted responses with start language "en": {statCountIf("startlanguage", "en", 1)}
  • Number of incomplete responses to this survey: {sum(statCount("id", 0),statCount("id")*-1)}
  • Number of responses submitted in 2022: {statCountIf("submitted", ">=2022-01-01")}
  • Number of submitted responses with answer Y to the question titled YesNo: {statCountIf(YesNo.sgqa, "Y")}
  • Number of responses, submitted or not, with answer A1 to the question titled Q01: {statCountIf(Q01.sgqa, "A1", 0)}
  • Check whether a short-text answer is unique among responses, evaluated only when moving to the next page (not submitted): {statCountIf(self.sgqa, self.NAOK, 0, 1)}