Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
BARC’s The BI Survey 19 makes it official. BI users love Qlik. GET REPORT
Highlighted
eduardo_dimperio
Valued Contributor II

Problem using "IF"

Hi,

Please, can someone tell me where im wrong

ANALISE_TMP:

LOAD

  ID_LEITURA,

    NAME_SYSTEM,

    NAME_GROUP,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    OID_METER,

    NAME_TYPE_METER,

    TYPE_CONSTANT,

    NAME_UC,

    ADDRESS_BLOCK_UC,

    DATE_READ AS DIA0,

    VALUE_READ,

    VALUE_READ*TYPE_CONSTANT AS LEITURA_FINAL,

    IF(OID_METER=PEEK(OID_METER) AND FLOOR(DATE_READ)=FLOOR(TODAY()),PEEK(VALUE_READ)) * TYPE_CONSTANT)-(VALUE_READ*TYPE_CONSTANT) AS CONSUMODIA0,

    IF(OID_METER=PEEK(OID_METER) AND FLOOR(DATE_READ)=FLOOR(TODAY()-1),PEEK(VALUE_READ)) * TYPE_CONSTANT)-(VALUE_READ*TYPE_CONSTANT) AS CONSUMODIA1,

    IF(OID_METER=PEEK(OID_METER) AND FLOOR(DATE_READ)=FLOOR(TODAY()-2),PEEK(VALUE_READ)) * TYPE_CONSTANT)-(VALUE_READ*TYPE_CONSTANT) AS CONSUMODIA2

  RESIDENT TMP2

    ORDER BY OID_METER, DATE_READ DESC;

I got this message:

Ocorreram os seguintes erros:

Syntax error, missing/misplaced FROM:

Tags (1)
1 Solution

Accepted Solutions

Re: Problem using "IF"

May be try this:

If(OID_METER = Peek(OID_METER) and Floor(DATE_READ) = Floor(Today()), (Peek(VALUE_READ) - VALUE_READ) * TYPE_CONSTANT) as CONSUMODIA0,

View solution in original post

9 Replies
Not applicable

Re: Problem using "IF"

I think that error means that if you are doing an order by, you have to load from a qvd or external source, not resident load?

Re: Problem using "IF"

May be try this:

If(OID_METER = Peek(OID_METER) and Floor(DATE_READ) = Floor(Today()), (Peek(VALUE_READ) - VALUE_READ) * TYPE_CONSTANT) as CONSUMODIA0,

View solution in original post

eduardo_dimperio
Valued Contributor II

Re: Problem using "IF"

Hey Sunny !

That works a litle bit, now im not have that red mark anymore, but still have the same erro when compile

ANALISE_TMP:

LOAD

  ID_LEITURA,

    NAME_SYSTEM,

    NAME_GROUP,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    OID_METER,

    NAME_TYPE_METER,

    TYPE_CONSTANT,

    NAME_UC,

    ADDRESS_BLOCK_UC,

   DATE_READ AS DIA0,

   VALUE_READ,

    If(OID_METER=  Peek(OID_METER) and Floor(DATE_READ)= Floor(Today()),(Peek(VALUE_READ)- VALUE_READ) * TYPE_CONSTANT)   as CONSUMODIA0,

    If(OID_METER=  Peek(OID_METER) and Floor(DATE_READ)= Floor(Today()-1),(Peek(VALUE_READ)- VALUE_READ) * TYPE_CONSTANT) as CONSUMODIA1,

    If(OID_METER=  Peek(OID_METER) and Floor(DATE_READ)= Floor(Today()-2),(Peek(VALUE_READ)- VALUE_READ) * TYPE_CONSTANT) as CONSUMODIA2,

  RESIDENT TMP2

    ORDER BY OID_METER, DATE_READ DESC;

Ocorreram os seguintes erros:

Syntax error, missing/misplaced FROM: ANALISE_TMP:

eduardo_dimperio
Valued Contributor II

Re: Problem using "IF"

No Sarah,  below i have the original code and it works fine. But im trying to improve.

They use 3 times the same code and i want to do replace with a multiple IF

ANALISE_TMP:

LOAD

  ID_LEITURA,

    NAME_SYSTEM,

    NAME_GROUP,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    OID_METER,

    NAME_TYPE_METER,

    TYPE_CONSTANT,

    NAME_UC,

    ADDRESS_BLOCK_UC,

    DATE_READ AS DIA0,

    VALUE_READ AS VALOR0,

  VALUE_READ*TYPE_CONSTANT AS LEITURA_INICIAL_DIA0,

  IF(OID_METER=PEEK(OID_METER),PEEK(DIA0)) AS DATA_HORA_LEITURA_FINAL_DIA0,

    IF(OID_METER=PEEK(OID_METER),PEEK(VALOR0)) * TYPE_CONSTANT AS LEITURA_FINAL_DIA0,

    (IF(OID_METER=PEEK(OID_METER),PEEK(VALOR0)) * TYPE_CONSTANT)-(VALUE_READ*TYPE_CONSTANT) AS CONSUMODIA0

  RESIDENT TMP2

    where FLOOR(DATE_READ)=FLOOR(TODAY())

    ORDER BY OID_METER, DATE_READ DESC;

MVP & Luminary
MVP & Luminary

Re: Problem using "IF"

There is a comma after your last field "CONSUMODIA2" which needs to be removed.

- Marcus

eduardo_dimperio
Valued Contributor II

Re: Problem using "IF"

Indeed Marcus, thank you.

eduardo_dimperio
Valued Contributor II

Re: Problem using "IF"

@SUNNY But why the code works only because i lower case the variables?

Re: Problem using "IF"

I did change some parenthesis in your script line

Mine

If(OID_METER = Peek(OID_METER) and Floor(DATE_READ) = Floor(Today()), (Peek(VALUE_READ) - VALUE_READ) * TYPE_CONSTANT) as CONSUMODIA0,

Vs.

Yours

IF(OID_METER=PEEK(OID_METER) AND FLOOR(DATE_READ)=FLOOR(TODAY()),PEEK(VALUE_READ)) * TYPE_CONSTANT)-(VALUE_READ*TYPE_CONSTANT) AS CONSUMODIA0,

eduardo_dimperio
Valued Contributor II

Re: Problem using "IF"

Right, Thank you again