Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

sum total in a field

Hello,

I need to solve this case

  date         Qt                  tot  

01/01/2011     10            10

02/02/2011     -5               5

03/02/2011     80             85

14/03/2011    -70             15  

I need to put the total value in a field. not in a table.

Please someone could to post the script?

Thanks

regards.

K.

1 Solution

Accepted Solutions
Jason_Michaelides
Partner - Master II
Partner - Master II

Here you go - should be working now.  You need to reset the Peek() on every change of Item:

Data:

LOAD * INLINE [

          post, item , QTY

          01/01/2011 , AAA, 100

          05/01/2011 , CCC, 26

          07/01/2011 , CCC, -4

          02/01/2011 , AAA ,-16

          03/01/2011, AAA, -4

          05/01/2011, FFF,70

] ;

Data_Ordered:

NoConcatenate

LOAD

          post

          ,item

          ,QTY

RESIDENT Data

ORDER BY  item, post;

DROP TABLE Data;

Data_Final:

NoConcatenate

LOAD

          post

          ,item

          ,QTY

          ,IF(item=Previous(item),NumSum(Peek('QTY_Accum'),QTY),QTY) as QTY_Accum

RESIDENT Data_Ordered ;

DROP TABLE Data_Ordered;

I've attached the file for you - hope it's what you're looking for.

Jason

View solution in original post

14 Replies
its_anandrjs
Champion III
Champion III

Hi,

As i understand i suggest you need to use Sum(Total tot) for the total value where ever you use this it is show total value of the tot.

I want to know where you want to put this value, please clear your requirements.

Regards,

Anand

lironbaram
Partner - Master III
Partner - Master III

hei look at this example

look at the load script

the trick is using numsum and peek functions

Not applicable
Author

thanks but I  nedd to group also by item:

date                 item       Qt                  tot  

01/01/2011          A            10            10

02/02/2011           A          -5               5

03/02/2011            A          80             85

14/03/2011            A        -70              15  

01/01/2011          B            1                1

02/02/2011           B           5                6

03/02/2011            B          80             86

14/03/2011            B        -70               66

Not applicable
Author

Please,

is not possible  to get total in field and groupping by Iyem and date ?

If I select Item 'A?  I need to see in field  every total referred to the item I selected.

best regards ,

Thanks

K

Not applicable
Author

You might be able to satisfy your requirement by defining a document variable named var_sumtot like this:    =sum(tot) and then whenever you use the variable var_sumtot it will contain the sum value you are looking for.

Not applicable
Author

please could to post the script?

Many thanks.

best regards,

K.

Not applicable
Author

I need to abtain thsi result in field:

for the "AAA" Item :
100
84
80

and for the "CCC" item:

26
22

IF I use this script it doesn't work becouse I'm not anle to
group by post and by Item. The value in total field was wrong:

inv:
load * INLINE [

post, item , QTY

01/01/2011 , AAA, 100
05/01/2011 , CCC, 26
07/01/2011 , CCC, -4
02/01/2011 , AAA ,-16
03/01/2011 , AAA, -4
];


load *,
numsum(peek('QTYTOTAL') , QTY) as QTYTOTAL
resident inv;

drop table inv ;

Please could to post the script solution for this question?
Many thanks
K.

lucas4bi
Partner - Creator
Partner - Creator

Hello,

first you need to order by ITEM and Post, then you can you that script code to calculate your progressive total:

load * INLINE [

post, item , QTY

01/01/2011 , AAA, 100
05/01/2011 , CCC, 26
07/01/2011 , CCC, -4
02/01/2011 , AAA ,-16
03/01/2011 , AAA, -4
] ORDER BY item, post;

load *,
numsum(peek('QTYTOTAL') , QTY) as QTYTOTAL
resident inv;

drop table inv ;

this should work,

let me know

Not applicable
Author

It wprks  just for a AAA item. The CCC value was wrong
Not for all.
Please chk below what I put in script:


  inv:
load * INLINE [

post, item , QTY

01/01/2011 , AAA, 100
05/01/2011 , CCC, 26
07/01/2011 , CCC, -4
02/01/2011 , AAA ,-16
03/01/2011 , AAA, -4
] ;

pk:
load
post as pos, item as itm,
QTY as qq
resident inv
//GROUP BY post, item
ORDER BY  item , post ;


load *,
numsum(peek('QTYTOTAL') , qq) as QTYTOTAL
resident pk  ;

drop table inv , pk ;


:((((


many thks.
K.