Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
eduardo_dimperio
Specialist II
Specialist II

Problem with function SUM()

Hi everyone,

I finally end my code (hope so), and thanks to all that spend some time to help me.

Now the last problem that i dont understand is using the SUN() function in the graphic.

If you look the image for the meter 32646 i only have 1 value 0,17 so when i use SUN(CONSUMO_REAL0), I expect output 0,17.

Why for all saints im getting 2,04 ????

Consumo_real.JPG

12 Replies
Clever_Anjos
Employee
Employee

12 times sounds me related to calendar problem (12 months) do you have a calendar into your app?

Does anytime you make a join into your script?

eduardo_dimperio
Specialist II
Specialist II
Author

Hi Clever,

More or less, I get some date values, but not using a calendar.

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,

    VALUE_READ,

    Date(DATE_READ) AS HORA,

    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,

    If(OID_METER=  Peek(OID_METER) and(Peek(VALUE_READ)- VALUE_READ)=0,OID_METER)  as EXCLUDE_METER

    RESIDENT TMP2

    ORDER BY OID_METER, DATE_READ DESC;

DROP TABLE TMP,TMP2;

Exclusao:

LOAD

  OID_METER,

  EXCLUDE_METER

RESIDENT ANALISE_TMP

WHERE NOT EXISTS (EXCLUDE_METER,OID_METER);

INNER JOIN (Exclusao)

LOAD

  OID_METER,

    ID_LEITURA,

    NAME_SYSTEM,

    NAME_GROUP,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    NAME_TYPE_METER,

    TYPE_CONSTANT,

    NAME_UC,

    ADDRESS_BLOCK_UC,

    DATE_READ AS DATA,

    VALUE_READ,

    CONSUMODIA0,

    CONSUMODIA1,

    CONSUMODIA2,

    If (OID_METER =PEEK(OID_METER), PEEK(CONSUMODIA0)- CONSUMODIA0) AS CONSUMO_REAL0,

    If (OID_METER =PEEK(OID_METER), PEEK(CONSUMODIA1)- CONSUMODIA1) AS CONSUMO_REAL1,

    If (OID_METER =PEEK(OID_METER), PEEK(CONSUMODIA2)- CONSUMODIA2) AS CONSUMO_REAL2,

    HORA

    RESIDENT ANALISE_TMP 

    WHERE   (HOUR(HORA)=2 OR HOUR(HORA)=5)

    ORDER BY OID_METER DESC;

   DROP TABLE ANALISE_TMP;

   

Teste:

LOAD

  OID_METER,

    ID_LEITURA,

    NAME_SYSTEM,

    NAME_GROUP,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    NAME_TYPE_METER,

    TYPE_CONSTANT,

    NAME_UC,

    ADDRESS_BLOCK_UC,

    DATA,

    VALUE_READ,

    CONSUMO_REAL0,

    CONSUMO_REAL1,

    CONSUMO_REAL2,

    HORA AS HORA_2

    RESIDENT Exclusao

    ORDER BY OID_METER DESC;

DROP TABLE Exclusao;

EXIT SCRIPT

Clever_Anjos
Employee
Employee

Try with this (if make sense)

Teste:

LOAD DISTINCT

  OID_METER,

    ID_LEITURA,

    NAME_SYSTEM,

    NAME_GROUP,

    NEIGHB_SYSTEM,

    CITY_SYSTEM,

    NAME_TYPE_METER,

    TYPE_CONSTANT,

    NAME_UC,

    ADDRESS_BLOCK_UC,

    DATA,

    VALUE_READ,

    CONSUMO_REAL0,

    CONSUMO_REAL1,

    CONSUMO_REAL2,

    HORA AS HORA_2

    RESIDENT Exclusao

    ORDER BY OID_METER DESC;