Calculation field -
We have had a Labour Cost rate change (based on Hours worked, either Category A or B), so would like to change an existing calculation field so that it would calculate on the original rate (36) if before 01/12/2022, and the new rate (42) if on/after 01/12/2022
Original Calculation is:
(@Labour Cost Hrs (A) ? @Labour Cost Hrs (A) : @Labour Cost Hrs (B)) * 36
What I have tried so far is not working (see below) - would appreciate guidance on how to correctly write the calc:
var result = "";
var DATE = (moment(@Date of Task).tz("Pacific/Auckland").format('DD/MM/YYYY'))
if (DATE <= '31/12/2022') {
result = (@Labour Cost Hrs (A) ? @Labour Cost Hrs (A) : @Labour Cost Hrs (B)) * 36;
}
if (DATE >= '01/01/2023') {
result = (@Labour Cost Hrs (A) ? @Labour Cost Hrs (A) : @Labour Cost Hrs (B)) * 42;
}
result;
-
Hi Tanya,
var type = (@Labour Cost Hrs (A) ? @Labour Cost Hrs (A) : @Labour Cost Hrs (B));
var date = Number (moment(@Date of Task).tz("Pacific/Auckland").format('YYYYMMDD'));
var rate = date <= 20221231 ? 36 : 42;
type*ratePlease note that I changed the date format to YYYYMMDD. In combination with the Number() function you get a eight digit number for each date (e.g 20230201 = 01.02.2023) which you then can compare to 20221231 (= 31.12.2022). This is only one of multiple possibilities to compare dates.
Rainer
Please sign in to leave a comment.
Comments
2 comments