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: 
Not applicable

Possible with IF?

Hello again,

I have the following IF, which works perfectly:

Load *,
If(Flag1) = 'S', tempSpend_NOK * -1, tempSpend_NOK) As ActualSpend_NOK,
If(Flag1 = 'S', tempTax_NOK * -1, tempTax_NOK) As ActualTax_NOK,
If(Flag1 = 'S', tempNetSpend_NOK * -1, tempNetSpend_NOK) As ActualNetSpend_NOK

Resident Table1;

Basically Flag1 determines if the signs should be inverted or not (*-1)....takes the gross, taxesm subtracts for net Norwegian Crowns

Bit I want to take things further, if possible.  I want to use a different field value based on different criteria.  Here is a non-working example:

Load *,

If(Flag1) = 1, TheField, TheField [WHERE Flag1 = 1) As WhatIsFlag1,

If(Flag2 = 1, TheField2, TheField2 * AnotherField [WHERE TheYear = 2015) As InverIfNeeded

Resident Table1;

Some of these might get quite involved so I wonder if I am even on the right track for this?  Is there a way to handle it in an IF...CASE....do it in SQL instead?

Thanks in advance for any advice.

10 Replies
Not applicable
Author

many thanks....do you know why I cannot mark a response as an answer...I am logged in but do not see the "mark as answer" any more....would like to give credit where credit is due...