Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum only different values

Dears,

How can I make QlikView to sum only the different values in the collumn B?

Check the example:

Column A | Column B

10 | 5
10 | 6
10 | 5
11 | 1
11 | 2
13 | 8
13 | 6
13 | 3
13 | 0

I would like to sum only 5+1+8, that will be 14
Actually, the result is: 5+6+5+1+2+8+6+3+0 = 36

So, how can I do it?

Thanks

11 Replies
Not applicable
Author

try

SUM(DISTINCT YOUR_FIELD)

Not applicable
Author

Érico,

I'm not sure if it will really solve my problem, because the colum that I want to sum is not the same of the one that will contain the criteria (values do be checked if it's different or not).

In the column A I have the filed criteria, and in the colum B I have the values to be sumed if the colum A value is different.

Thanks for your attention

Not applicable
Author

Follow attached is an example.

I want to check the values in the colum A, and sum the valus in the colum B.

In the example, I'm suming the distinct values in the colum B. But it's wrong.

How Can I do it?

Thanks

Not applicable
Author

I don´t know what´s your rule, i don´t understand your example.....you sum just 5 + 1 + 8 and have another values differente than column A lile third line....value 6....

You can do something ike this...depends your rule....

SUM( IF(Column B <> Column A, Column B))

Not applicable
Author

I'll try to be less confused. Smile

I have 2 columns. The column A and the column B.
In the column A I have the code and in the column B I have the value.

The system that generate this excel file is very complex and they do this logic:
In the first line they give you the total value, and in the next lines they specify the values of all the services realized that compose the total value in the first line.

Check this example:

Column A | Column B | Description
56 | 100 | Car service
56 | 30 | Washing
56 | 20 | Cleaning
56 | 50 | Repair
57 | 15 | Tire replacement
57 | 10 | 2 Tires
57 | 05 |Balancing

So, I can't sum all the values (100+30+20+50+15+10+05) coz I would be duplicating the values. What I need to do is: Sum only the first different value in the column A. (100+15)

The values after the first different value in the columbn A, just describes the total amount.

So, how can I sum, in the column B, only the first different values in the columbn A?

Is is clear now?

Thanks so much for your attention,
Best regards;

Not applicable
Author

Clear now.....you wanna take just a "Total" values....same the first line each code.....ok?

You have a lot of options....

You can try on load.....make a flag on that lines (Total) if always be on the first line....

on the load you can create a nem column for a flag.....use a rule like this

IF(Column A <> PREVIOUS(Column A), 'TOTAL') AS FLAG

and in your aplication......

SUM(IF(FLAG='Total', Column B))

A litle bit confused....hope it helps you

johnw
Champion III
Champion III

For your specific example, consider sum("Column B")/2. If the details always add up to the total, then the simple sum is always twice as big as it should be, so just divide by 2.

The flag approach would probably give better performance, though, at least if you use set analysis.

sum({<FLAG={'Total'}>} "Column B")

Not applicable
Author

Érico,

Acabei de ver que você é brasileiro, então acho melhor conversarmos emportuguês!

Então, o que acontece é o seguinte. Eu tenho na coluna A o código e na coluna B o valor.

Porém por regra do sistema, ao fazer a extração ele sempre carrega nesta ordem:

Coluna A | Coluna B | Descrição
30 | 100 | Carro
30 | 40 | Lavagem
30 | 60 | Higienização
31 | 400 | Compra de avião
31 | 200 | ERJ-145
31 | 200 | Phenom 100
...

Ou seja, na primeira linha temos o código 30 que diz respeito a algo efetuado em um carro que custou 100 reais. Então na próxima linha ainda temos o código 30 e o valor 40 reais que se refere a lavagem e na próxima linha o valor de 60 reais que refere a uma higienização. Ou seja as duas próximas linhas descrevem o componente dos 100 reais. Ou seja, os 100 reais de gasto que tivemos foi dividido em 40 para lavagem + 60 para higienização.

Já na próxima linha temos o código 31, ou seja é uma nova tarefa que não diz mais respeito a 30. e custou 400 reais. as duas linhas subsequentes descrevem o que aconteceu. Sendo 200 reais para a compra de um ERJ e 200 para a compra de um Phenom 100.

Portanto eu não posso somar tudo (100+40+60+400+200+200) porque o primeiro 100 já é a soma de 40+60 e o 400 já é a soma de 200+200. Portanto eu devo somar só o 100+400.

A regra seria: Somar os primeiros valores na coluna B que tiverem um valor na coluna A diferente do valor da coluna a -1.


Acho que agora está um pouco mais claro,


Desculpe por te atrapalhar tanto, é que preciso muito disso!


Muito obrigado;
Boa tarde

erichshiino
Partner - Master
Partner - Master

Hi,

I solved it by a inter-record analysis on the script.

Please, check the file attached.

Hope it helps.

(P.S I'm also from Brasil)