Using Java Script Computed Columns

advertisement
Using Java Script in Hyperion Computed Columns
The programming language that is used in the Results Section of a Hyperion document
is java script. It can be used to calculate new columns, based on values in existing
columns. The calculation can involve various Functions some of which are math
functions, some logic, some conversion type functions. When you find yourself
calculating multiple computed columns, one depending on the last, you can combine
columns in one calculation using java script programming syntax.
EXAMPLE – Calculating GPA from a Specified Set Of Classes
Here is a base set of classes for which we would like to automatically calculate a GPA.
Six separate computed columns can be used to calculate GPA as follows:
1. Grade Points
if(Crse_Grade_Input== "A+") 4.333;
if(Crse_Grade_Input== "A") 4.000;
if(Crse_Grade_Input== "A-") 3.667;
if(Crse_Grade_Input== "A+") 4.333;
if(Crse_Grade_Input== "B") 3.000;
if(Crse_Grade_Input== "B-") 2.667;
if(Crse_Grade_Input== "B+") 3.333;
if(Crse_Grade_Input== "D") 1.000;
if(Crse_Grade_Input== "D@") 0.000;
if(Crse_Grade_Input== "E") 0.000;
if(Crse_Grade_Input== "C+") 2.333;
if(Crse_Grade_Input== "C") 2.000;
2.
3.
4.
5.
6.
Unit for Credit - if(Grade_Points!=null)Unt_Taken
Points x Hours - Unit_for_Credit * Grade_Points
Total Hours for Credit - Sum ( Unit_for_Credit, Emplid )
Total Points - Sum ( Points_x_Hours, Emplid )
GPA - Total_Points / Total_Hours_for_Credit
OR… you can do it in ONE COLUMN as shown next:
// Declare variables
var Grade_Points, Unit_for_Credit, Points_x_Hours, Total_Points, Total_Hours_for_Credit;
//Calculate Grade Points
if(Crse_Grade_Input== "A+") Grade_Points = 4.333;
if(Crse_Grade_Input== "A") Grade_Points = 4.000;
if(Crse_Grade_Input== "A-") Grade_Points = 3.667;
if(Crse_Grade_Input== "A+") Grade_Points = 4.333;
if(Crse_Grade_Input== "B") Grade_Points = 3.000;
if(Crse_Grade_Input== "B-") Grade_Points = 2.667;
if(Crse_Grade_Input== "B+") Grade_Points = 3.333;
if(Crse_Grade_Input== "D") Grade_Points = 1.000;
if(Crse_Grade_Input== "D@") Grade_Points = 0.000;
if(Crse_Grade_Input== "E") Grade_Points = 0.000;
if(Crse_Grade_Input== "C+") Grade_Points = 2.333;
if(Crse_Grade_Input== "C") Grade_Points = 2.000;
//Set Unit for Credit to all courses that have grades
if(Grade_Points!=null) Unit_for_Credit = Unt_Taken;
//Grade Points multiplied by Units for Credit
Points_x_Hours = Unit_for_Credit * Grade_Points;
//Sum Total Hours for credit by student
Total_Hours_for_Credit= Sum ( Unit_for_Credit, Emplid );
//Sum Points by student
Total_Points = Sum ( Points_x_Hours, Emplid );
//Calculate GPA
Total_Points / Total_Hours_for_Credit;
The //is a comment character. All the lines starting with // could be left out and you
would get the same thing. It is a nice way of documenting what you are doing however!
You must begin by declaring FIVE variables (one less than the number of columns).
They are the same name as the individual columns were. The five variables that you
declare will be used in the one column to calculate the last GPA value.
Notice the difference in syntax from the original columns. Each variable is assigned a
value with an equal sign.
The very last calculation needs no equal sign, it uses the previously created variables to
calculate the GPA. NOTE: To make this work, you always have to name your data
elements the same thing!
Download