Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
trishita
Contributor

How and where to write conditional statement in qlikview

I have two fields .

Deviation after sounding and Difference vs Log survey:

I want to write a code that if the  difference between them is less than 2 then a new column will display yes against the value or else no.

if (Deviation after sounding) - (Difference vs Log survey) <=2 then (NEW COLUMN ) = "Correction done"

or else "Correction Not Done"

10 Replies
mwoolf
Honored Contributor II

Re: How and where to write conditional statement in qlikview

In script:

if(rangesum([Deviation after sounding],-[Difference vs Log survey])<=2,'Correction done','Correction not done') as NewField

vishsaggi
Esteemed Contributor III

Re: How and where to write conditional statement in qlikview

Did you try like:

LOAD field1, field2,

           if ((Deviation after sounding - Difference vs Log survey) <=2, "Correction done", "Correction Not Done") AS NewFieldName

FROM yoursourceTableName;

trishita
Contributor

Re: How and where to write conditional statement in qlikview

I have not done it in the table as the two fields are coming from different tables

trishita
Contributor

Re: How and where to write conditional statement in qlikview

Why do we need rangesum? Can I do it in the edit expression of chart properties(as I am using a standard table chart)

mwoolf
Honored Contributor II

Re: How and where to write conditional statement in qlikview

You need rangesum if either of the two fields can ever be null. F1-F2 will yield null if either is null.

Yes, you can do it in a chart expression. Generally it is better (faster) to do as many calculation is script as is feasible.

trishita
Contributor

Re: How and where to write conditional statement in qlikview

Hi I tried with the following code:

if(rangesum(SoundingCorrections.DEVIATION_AFTER_SOUNDING,-[Summary.Difference Log vs Survey])>= 0,'Correction done','Correction not done')

DEVIATION AFTER SOUNDING HAS THE FOLLWOING VALUES. = -42,  -42,  -42,  -42

Difference Log vs Survey HAS THE FOLLWOING VALUES = 0,  -42.68,  -16,  -7.89

But for all the values they are showing 'Correction Not Done' Which should not be true as the second value is clearly greater than 0

mwoolf
Honored Contributor II

Re: How and where to write conditional statement in qlikview

Add an expression:

rangesum(SoundingCorrections.DEVIATION_AFTER_SOUNDING,-[Summary.Difference Log vs Survey])


so you can see the values.


Can you share the qvw?

vishsaggi
Esteemed Contributor III

Re: How and where to write conditional statement in qlikview

Can you share your data model and the script you are trying?

shiveshsingh
Honored Contributor

Re: How and where to write conditional statement in qlikview

Can you share the data and script?

Community Browser