# QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Not applicable

## Total does not add up

Hi

I have a problem with a pivot table where the total do not add up.

I have a buying template and want to calculate the stock required which is  (if negative , give zero):

if(Average*7-[Stock on Hand]+[Sales Order]<0,0,Average*7-[Stock on Hand]+[Sales Order]) .

The only problem im having is that total of the "stock required"  is incorrect.  The total should be 10,697 and not 9768.

im aware that the solution works for a straight table.  I want it to work for a pivot table.

I have attached the Qlikview Model as well as the data (in excel)

kind regards

Nayan

1 Solution

Accepted Solutions
Not applicable

PFA

5 Replies
Not applicable

## Re: Total does not add up

Hi

Try like this

=If(RowNo() = 0 or IsNull(RowNo()), Sum(if(Average*7-[Stock on Hand]+[Sales Order]<0,0,Average*7-[Stock on Hand]+[Sales Order])),

if(Average*7-[Stock on Hand]+[Sales Order]<0,0,Average*7-[Stock on Hand]+[Sales Order]))

Not applicable

PFA

Not applicable

## Re: Total does not add up

You can look into the method

Sum of rows in pivot tables using adavanced aggregation

in the Help.

This will look like

=sum( aggr(

if(Average*7-[Stock on Hand]+[Sales Order]<0,0,Average*7-[Stock on Hand]+[Sales Order])

,[Component Code],[ITEM  CODE]))

Probably there is even an easier solution.

Not applicable

## Re: Total does not add up

Hi All

Thank you for the responses.  It works on the QV Template given.  I'm going to try it out on my actual model and will let all know regarding the outcome.

kind regards

Nayan

Not applicable

## Re: Re: Total does not add up

Hi Mayil

However , if i use the heading names in the stock required , the formula does not work.  (see model attached).

Can you tell me why?

I change the names of the headings of the 3 columns :

ie  Average  = NewAVG

Stock on Hand = NewSOH

Sales Order = NewSO

In my actual buying temple, each of the columns is a complex if formula, hence i use the name of the headings in my stock required formla.

kind regards

Nayan

Community Browser