Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Save the Date: QlikWorld Online, June 24-25, 2020. Free global virtual event for data integration and data analytic gurus. Register Today
Highlighted
Valued Contributor 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
Highlighted

Re: Problem using IF statement

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
Highlighted
Honored Contributor

Re: Problem using IF statement

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

Highlighted
Valued Contributor II

Re: Problem using IF statement

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

Highlighted

Re: Problem using IF statement

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.

Highlighted
Valued Contributor II

Re: Problem using IF statement

Didn't understant,

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

Highlighted

Re: Problem using IF statement

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

Highlighted
Honored Contributor II

Re: Problem using IF statement

You might be missing single quotes in expression.

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

Highlighted
Valued Contributor II

Re: Problem using IF statement

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

Highlighted
Valued Contributor II

Re: Problem using IF statement

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