Hello,
I have a table:
| Name | Score | Reason | Score2 |
| John | 100 | Test | |
| Dan | 95 | HW | |
| Elli | 92 | Sick | |
I want to add a JSL formula to "Score2" column which takes the value from "Score" unless there is the word "Sick" in the "Reason" column:
| Name | Score | Reason | Score 2 |
| John | 100 | Test | 100 |
| Dan | 95 | HW | 95 |
| Elli | 92 | Sick | 100 |
Below is what I have but it doesn't perform the Else as I need it to:
dt1 <<NEW column=""></NEW>
Thank you in advance.
You are creating a numeric column, but you are trying to give it a character string column value of "100". By placing quotes around the 100, you are telling it to make the value a character string. Leave the quotes out to assign a numeric value.
dt1 << New Column( "Score2",
Numeric,
"Continuous",
formula( If( :Reason == "Sick", 100, :Score ) )
);
There is also a possible problem if the column Score is not a numeric column in your data table. If it is a character column, change your code to:
dt1 << New Column( "Score2",
Numeric,
"Continuous",
formula( If( :Reason == "Sick", 100, num( :Score ) ) )
);