Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem with nested if-statements

I have the following expression:

if(FVCON_ID_CONTAT=5,

    if(date#(trim(right((FVCON_DATA_FI),2) & '/' & mid((FVCON_DATA_FI),5,2) & '/' & Left((FVCON_DATA_FI),4)),'YYYYMMDD') =

        (date#(trim(right(Date(FVCON_TS_ESTR,'YYYYMMDD'),2) & '/' & mid(Date(FVCON_TS_ESTR,'YYYYMMDD'),5,2) & '/' & Left(Date(FVCON_TS_ESTR,'YYYYMMDD'),4)),'YYYYMMDD')

                    or

                (FVCON_DATA_FI=0)),'aperte','chiuse')) as SelettorePraticheAperteChiuse,

The problem is that the value of SelettorePraticheAperteChiuse is only chiuse but I would that have the value aperte and chiuse.


Where is the problem ?

Thanks, Giovanni

12 Replies
Anonymous
Not applicable
Author

The problem is more likely with the data than with the nested if, but your expression is way more complex than it has to be, and it's not clear what to return if FVCON_ID_CONTAT<>5 (I added chiuse).

See what I got after cleanup:

if(FVCON_ID_CONTAT=5,
    if(date(date#(FVCON_DATA_FI,'YYYYMMDD')) = date(FVCON_TS_ESTR)
   or FVCON_DATA_FI=0),'aperte','chiuse'),
   'chiuse') as SelettorePraticheAperteChiuse,

Not applicable
Author

The solution the you write is wrong.

I obtain only the value chiuse for SelettorePraticheAperteChiuse.


I don't know how can I write the expression ...

Anonymous
Not applicable
Author

If its wrong its not a solution .  And, I only simplified your expression, to show how to write it in a more clear way.  Back to my major point: "The problem is more likely with the data...".  If you need a solution, you have to upload your application.

Not applicable
Author

I have attached the file. On the line 437 there is the expression ....

Anonymous
Not applicable
Author

Giovanni,

Can you reduce the file?  To 1 MB or less please?

From your last comment it looks like the expression is in the script, not in a front end object.  It make it harder to troubleshoot because I cannot reload, so I have to ask a few questions.

My assumption is that FVCON_DATA_FI and FVCON_TS_ESTR are dates in different formats, and that your want result to be 'aperte' if the dates are equal or FVCON_DATA_FI=0, but only when the FVCON_ID_CONTAT=5.

So, the questions are:

- What is format of FVCON_DATA_FI?

- What is format of FVCON_TS_ESTR?

- What should be the result if FVCON_ID_CONTAT <> 5?

Thanks,

Michael

Not applicable
Author

i tried to open you document.. but it is not opening

Not applicable
Author

If I use the following expression

if

    (FVCON_ID_CONTAT=5,

        if(

            (date#(trim(right((FVCON_DATA_FI),2) & '/' & mid((FVCON_DATA_FI),5,2) & '/' & Left((FVCON_DATA_FI),4)),'YYYYMMDD') =

                         date#(trim(right(Date(FVCON_TS_ESTR,'YYYYMMDD'),2) & '/' & mid(Date(FVCON_TS_ESTR,'YYYYMMDD'),5,2) & '/' & Left(Date(FVCON_TS_ESTR,'YYYYMMDD'),4)),'YYYYMMDD')

             or FVCON_DATA_FI=0    

            ),'aperte','chiuse'),'chiuse')     as SelettorePraticheAperteChiuse,   

Now I obtain the value aperte and chiuse but there is a problem.

I get the values of aperte/chiuse for FVCON_ID_CONTAT that are different from the condition set FVCON_ID_CONTAT = 5.


What I wrong ?

Not applicable
Author

Hi gys, the solution that you write me are wrong ...

Please help me ...I'm new of QlikView and It's dificult to me to resolve this problem.

Thanks a lot.

Not applicable
Author

Hi Giovanni

I think you might be using the OR incorrectly and need to change it to read as below for it to work

if(FVCON_ID_CONTAT=5,

   if((date#(trim(right((FVCON_DATA_FI),2) & '/' & mid((FVCON_DATA_FI),5,2) & '/' & Left((FVCON_DATA_FI),4)),'YYYYMMDD')

   =date#(trim(right(Date(FVCON_TS_ESTR,'YYYYMMDD'),2) & '/' & mid(Date(FVCON_TS_ESTR,'YYYYMMDD'),5,2) & '/' & Left(Date(FVCON_TS_ESTR,'YYYYMMDD'),4)),'YYYYMMDD')

   or

   date#(trim(right((FVCON_DATA_FI),2) & '/' & mid((FVCON_DATA_FI),5,2) & '/' & Left((FVCON_DATA_FI),4)),'YYYYMMDD')

   =FVCON_DATA_FI=0),'aperte','chiuse'),'chiuse')     as SelettorePraticheAperteChiuse 

Hope this helps you

Helen