/
Monthly Grouping Variable

Monthly Grouping Variable

Description

Use a date field to create a variable that separates the date values into Months.  For instance, a table showing enrollment status over the year (see below).


How To

Use the code below to create the calculated variable.  

Variable Finder tab:  Add a date variable by which the data will be grouped (columns)

On Expression tab:

Exclude Previous Years Approach:

 function main() {

   if (isNull(V1))  {

         return 14;   

   } else {

      var myMonth = V1.getMonth() + 1;  // JavaScript has Jan=0, Feb=1, etc., thus add 1 so that Jan=1, Feb=2, etc.

      var myYear = V1.getFullYear();     

      if (myYear <= 2016) {        // previous year = 2016, replace as appropriate

           return 13;     

     } else {

           return myMonth;

     }   

 }

}

On the Pick List tab:

Create  (e.g., 1 = January, 2 = February, etc. through 13="Previous Year"; 14 = "Missing Date")

 

 

Alternate method that ignores the year:

In this example, don't need a pick list option for 12/Previous Year

function main() {

if (isNull(V1)) {    // check to make sure the date field exists

   return 13;

} else {

    var myMonth = V1.getMonth();

    return myMonth;

}

}






Related content

Days To Event Categorical Variable
Days To Event Categorical Variable
More like this
Using Dates with JavaScript
Using Dates with JavaScript
More like this
Variables in Rows
Variables in Rows
More like this
Scripting in Report Templates
Scripting in Report Templates
More like this
Working with dates in the script
Working with dates in the script
More like this
Create a Calculated Variable in Data Sets
Create a Calculated Variable in Data Sets
More like this