Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Daryn
Creator
Creator

SUM two values (each is calculation of 3 fields) but only add the second value if the first was zero

Hi, 

Sorry to trouble the community once more!

In load script I am calculating  and creating a new field [Line hours] from a field of minutes (VGW02 or VGW03), a base quantity and a confirmed qty divided by 60 for hours. 

((([VGW03]/[BMSCH]) * [GMNGA])/60) + ((([VGW02]/[BMSCH]) * [GMNGA])/60) as [Line Hours],

This is based on two calculations, the first half is machine hours  ((([VGW03]/[BMSCH]) * [GMNGA])/60), the second part Labour hours  ((([VGW02]/[BMSCH]) * [GMNGA])/60) .

The calculation works, but I have an issue with end values where VGW03 and VGW02 both have positive values (one or the other should normally be 0, but this is not always the case).

As such I only want it to add the second part    + ((([VGW02]/[BMSCH]) * [GMNGA])/60)     if the first half calculated as 0.

In theory:

((([VGW03]/[BMSCH]) * [GMNGA])/60) = line hours

if line hours = 0 then add this......

 + ((([VGW02]/[BMSCH]) * [GMNGA])/60) 

= line hours

 

Hope that makes sense, I am probably over thinking it!

Regards Daryn

Labels (1)
1 Solution

Accepted Solutions
jwjackso
Specialist III
Specialist III

Try this

If (VGW03 = 0,((([VGW02]/[BMSCH]) * [GMNGA])/60),((([VGW03]/[BMSCH]) * [GMNGA])/60)) as [Line hours]

 

View solution in original post

2 Replies
jwjackso
Specialist III
Specialist III

Try this

If (VGW03 = 0,((([VGW02]/[BMSCH]) * [GMNGA])/60),((([VGW03]/[BMSCH]) * [GMNGA])/60)) as [Line hours]

 

Daryn
Creator
Creator
Author

Hi and thank you for taking the time to read and reply.

This works perfectly!

Many thanks have a great Friday and weekend.

Regards,  Daryn