Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

sum expression error

Hi everyone,

      i want to show you an strange issue.

I have the table 1.

table 1.png

I don't know why but when i use the sum expression the values are wrong (see table 2)table 2.png)...

The real value of sum is 51.

Can someone help me?

Thanks!

19 Replies
Not applicable
Author

Hi,

As already mentioned earlier by Jagan, your table has got duplicate keys.

I have added one chart which describes how many times your keyfield is duplicated. Total of the same is number of rows appearing in your subsription table.

Sum of the field is also justified as breakup explains the same.

Regards

Amar Nath

Not applicable
Author

Hi,

      Hope attached file helps you.

Regards,

Sampath Kumar G

Not applicable
Author

Thank you very much Sampath, Amar and Jagar....

What can i do to resolve the problem of Key duplication with the inner join?

jagan
Luminary Alumni
Luminary Alumni

Hi,

If you want to eliminate duplicate rows try using Distinct during load.

LOAD DISTINCT

*

FROM DataSource;

This will remove the duplicate rows.

Or

If you want to keep all the rows as such

introduce a new field like RowNo().  Check file attached in above post.

Regards,

jagan.

Not applicable
Author

Thanks Jagan!

So….if i need to use inner join between two tables then i have to use a distinct load?

I mean, always inner join create duplícate keys? there is another function to use to avoid this?

De: jagan mohan

Enviado el: viernes, 20 de abril de 2012 11:55 a.m.

Para: Pauza, Gerardo

Asunto: - Re: sum expression error

QlikCommunity <http://community.qlik.com/index.jspa>

Re: sum expression error

created by jagan mohan <http://community.qlik.com/people/jagan> in New to QlikView - View the full discussion <http://community.qlik.com/message/212402#212402

sebastiandperei
Specialist
Specialist

Hi Gera!!!

Usá

Sum(Aggr(Max( DEAL_EXTERNALS.quantity_A), DEAL_EXTERNALS.deal_externals_id_A))

, y podés dejar el script así como está.

El problema está en que tenés todos los valores repetidos un montón de veces. Inner Join no te duplica valores, Inner Join te quita las no coincidencias entre las tablas. Los valores duplicados podés tenerlos en cualquiera de los dos qvd que joineás.

Probalo!!

Not applicable
Author

Sebastian,

    gracias por la respuesta.

Lo que no llego a entender es porque tengo los valores duplicados, si lo unico que hago es hacer un inner join entre dos tablas con distinta informacion salvo por el user_id.

Cual seria la forma correcta de unir estas dos tablas sin generar duplicados?

Te paso el inner join que tengo ahora:

SUBSCRIPTIONS_A:

LOAD

       user_id as %Key_USER_ID_A,

    user_id as user_id_A

     FROM [..\QVD\SUBSCRIPTIONS.QVD] (qvd);

inner Join

load

    Year(created) & Num(Month(created),'00') & Num(Day(created),'00') as %Key_CREATED_DEAL_EXTERNALS,

    user_id as %Key_USER_ID_A,

    user_id as user_id_A,

    quantity as quantity_A,

    id as deal_externals_id_A

FROM [..\QVD\DEAL_EXTERNALS.QVD] (qvd)

where `external_status` = 'A';

Gracias

gerardo

sebastiandperei
Specialist
Specialist

hay que ver qué hay en los QVD...Intuyo q están en SUBSCRIPTIONS. Qué hay acá? Lo más probable es que tengas varios registros por cada user_id.

Le estás diciendo a Qlikview:

1- Leé las claves de SUBSCRIPTIONS.QVD y creá dos campos con nombres diferentes por cada una (acá es muy probable que estén repetidos)

2- Leé de DEAL_EXTERNALS.QVD tales datos, y emparentalos con cada clave leída.

Si tenés por ejemplo user_id A, A, A, B, B, C, C, C, C,... te va a poner los datos de quantity que se corresponden en la segunda tabla con A, 3 veces, con B, 2, y así....

Tenés que tener un buen conocimiento de qué hay en cada qvd antes de leerlo.

Not applicable
Author

Perfecto! Excelente explicación.

Gracias

gerardo

De: Sebastian Pereira

Enviado el: lunes, 23 de abril de 2012 01:56 p.m.

Para: Pauza, Gerardo

Asunto: - Re: sum expression error

QlikCommunity <http://community.qlik.com/index.jspa>

Re: sum expression error

created by Sebastian Pereira <http://community.qlik.com/people/sebastiandpereira> in New to QlikView - View the full discussion <http://community.qlik.com/message/212893#212893

sebastiandperei
Specialist
Specialist

Dame un Resuelto! je