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;
}
}