Filter or remove respondents

Updated at September 13th, 2022

This tutorial shows data processing code to remove data from a project on a per respondent level. 

The code to remove respondents can be added to static data processes or pre-cal since it is lightweight, and  doesn't impact processing time when opening the project. 

Code

First find a variable that can be used to identify respondents. Typically, there is a respondentid or respid column in the data. Edit the code below to reference the correct values (e.g. "101") and filter out the relevant respondents. 

The logic is straight forward.The "if" statement sets a condition to return false for respondents that you want to remove and return true for those you want to keep. This code can go into project pre-calculate or a data process. 

rows = rows.filter(function(row) { 
    if (row.respid == "101") return false      // remove respondent with respid ="101"
    if (row.respid == "102") return false      // remove respondent with respid ="102"
    if (row.status == "INCOMPLETE") return false // remove incomplete respondents

    return true                                // do not remove anyone else
})

return rows;



Reminder: For data processes, "Save" and "Run" the process after you are done editing the code view. To use the result of the process as the primary data for the project, you will need to set it as "Primary".
Data processes are specific to each project, and your code may not look identical to our example. 

Was this article helpful?