Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
eduardo_dimperio
Specialist II
Specialist II

Problem using IF statement

Hi everyone,

I having extremely dificult using IF statement in QS, for me is very diferente that other languages like C,C# or PHP

Im trying this:

If (OID_METER = Peek(OID_METER),

       If (Floor(DATE_READ)= Floor(Today()),

             (Peek(VALUE_READ)- VALUE_READ) * TYPE_CONSTANT   as CONSUMODIA0,

              HORA as HORA0

           )

        If (Floor(DATE_READ)= Floor(Today()-1),

        (Peek(VALUE_READ)- VALUE_READ) * TYPE_CONSTANT   as CONSUMODIA1,

         HORA as HORA1

            )

        If (Floor(DATE_READ)= Floor(Today()-2),

        (Peek(VALUE_READ)- VALUE_READ) * TYPE_CONSTANT   as CONSUMODIA2,

         HORA as HORA2

            )

  )

The error is ')' expect, but where? i close all "()"

1 Solution

Accepted Solutions
Anonymous
Not applicable

I mean that you can only have a single AS FIELDNAME at the end of an if statement.

Whilst I am not sure what you are trying to do, I suspect that creating a flag could be part of what you need to do :

    If (OID_METER = Peek(OID_METER), 0, 1)      as [New Meter Flag] ,


The rest of what you need may be suitable for sorting in the front end.  But there again maybe not as I am guessing at your needs.


View solution in original post

8 Replies
rittermd
Master
Master

In the editor if you click your mouse to the right of a ) it will show you the matching ( on the other end.

eduardo_dimperio
Specialist II
Specialist II
Author

Yep and i found a match for everyone. I even count 40 bracket. A pair number

Anonymous
Not applicable

In the load script the result of an if statement needs to be assigned to one and only one output field.

You are attempting to assign values to multiple output fields which is invalid.

eduardo_dimperio
Specialist II
Specialist II
Author

Didn't understant,

You mean that part where a use "AS CONSUMODIA0" and " AS HORA0", i have to choose between one or other?

Anonymous
Not applicable

I mean that you can only have a single AS FIELDNAME at the end of an if statement.

Whilst I am not sure what you are trying to do, I suspect that creating a flag could be part of what you need to do :

    If (OID_METER = Peek(OID_METER), 0, 1)      as [New Meter Flag] ,


The rest of what you need may be suitable for sorting in the front end.  But there again maybe not as I am guessing at your needs.


MK9885
Master II
Master II

You might be missing single quotes in expression.

I wouldn't know where to add but ' may solve the issue

eduardo_dimperio
Specialist II
Specialist II
Author

Hi Bill,

Thanks for the help, i trying create 2 fields inside a single if indeed, if my date is today at the same time I add value to field CONSUMODIA0 and a date to HORA field. Pity it can't be done

eduardo_dimperio
Specialist II
Specialist II
Author

Yes, i sad that in first coment, but thanks anyway