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: 
Not applicable

Calculate values on same column

Hi,

i am very new to Qlikview and i have a simple question:

I have a table with the following structure:    

TypeQuantity
Sale5
Sale10
Return2
Sale15
Return5

I want to add all Sales and subtract all Returns. So, for this example, i want to calculate the:

(5+10+15)-(2+5)

Althougth i searched it on the internet, i wasn't able to find something helpful. So, any advice will be approciated.

Thanks in advance and sorry for my bad english,

Michael

1 Solution

Accepted Solutions
MarcoWedel

maybe

Load Type,

         If(Type='Return',-Quantity,Quantity) as Quantity

From YourSource



regards


Marco

View solution in original post

12 Replies
shree909
Partner - Specialist II
Partner - Specialist II

Try this Sum({<Type={'Sale'}>}Quantity) -Sum({<Type={'Return'}>}Quantity)

vishsaggi
Champion III
Champion III

My be this?

= Sum({< Type = {'Sale'} >}Quantity) - Sum({< Type = {'Return'} >}Quantity)

sunny_talwar

I like what the above two have provided, but have lately developed a habit of using RangeSum().


RangeSum(

Sum({< Type = {'Sale'} >}Quantity),

-Sum({< Type = {'Return'} >}Quantity))

MarcoWedel

another solution might be:


Sum(If(Type='Return',-1,1)*Quantity)

hope this helps

regards

Marco

Not applicable
Author

Thank you for your answers! I have one more question. Is it possible to made this calculation from the edit script, so it won't be necessary to make the same calculation again and again. I am wondering if there is something like Marco's solution, for example :

Load:          

Type,

Quantity

If(Type=Return)

then Quantity*(-1)

MarcoWedel

maybe

Load Type,

         If(Type='Return',-Quantity,Quantity) as Quantity

From YourSource



regards


Marco

susovan
Partner - Specialist
Partner - Specialist

Hi Mich,

You can also try this below expression

=Sum({<Type={'Sale'}>}Quantity)-Sum({<Type-={'Sale'}>}Quantity)

Warm Regards,
Susovan
Not applicable
Author

Hi Mich,

Try like this :

= Num(Sum(Sum({< Type = {'Sale'} >}Quantity),-Sum({< Type = {'Return'} >}Quantity)))

=Sum(Sum({< Type = {'Sale'} >}Quantity),-Sum({< Type = {'Return'} >}Quantity))

= rangeSum(Sum({< Type = {'Sale'} >}Quantity),-Sum({< Type = {'Return'} >}Quantity))

You can try this in Load statement:

Example:

Load

         Type,

         If(Type='Return',-Quantity,Quantity) as Qty

From Source_table.

Thanks,

Nandu

Not applicable
Author

Thanks for your suggestions. It is working fine right now, based on Marco's reply.