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

PIVOTTABLE/SUM QUERY

Hello

I am relatively new to Qlikview and I am stuck on what i am sure is an easy problem

I currently have a Pivottable which displays the Sales Volume listed by Type and Date.

EXAMPLE

PERIOD 1 2

TYPE A 100 200

TYPE B 300 200

What i need is a 3rd Column which gives me the difference between the previous columns, so for TYPE A this would be 100, for TYPE B this would be -100

I know i need to use an expression but i can;t work it out. The date is on a group function so the data can be displayed in different forms

I hope this makes sense

thanks

4 Replies
Not applicable
Author

If the sequence of the columns doesn't change, you could use the following expression for the third column


Column(1)-Column(2)


Or just create an expression (new column) that subtracts the two expressions


(expression1) - (expression2)


Not applicable
Author

Hi

Firstly thanks for taking the time to reply and help, much appreciated

However, the Pivot table I have shows the number of orders, displayed by Type, by either Period, Week, Day etc [depending on Group]

What i would like to show is the number of orders in one column and the difference compared to the previous in the next, and then repeat this for the next , for as many columns as required.

EXAMPLE

DATE 1 2 3

NUM DIFF NUM DIFF NUM DIFF

TYPE A 100 - 50 -50 75 25

TYPE B 200 - 100 100 75 -25

What expression would i need for this?

Sorry i wasn;t overly clear in my Previous Post.

Thanks

Not applicable
Author

Ah, this looks more like you have a dimension DATE you want to pivot.

I think you want to use the Before function.

From the help:

before( [ total ] expression [ , offset [,n ]] )

Returns the value of expression evaluated with a pivot table's dimension values as they appear in the column before the current column within a row segment in the pivot table. This function returns NULL in all chart types except pivot tables.

On the first column of a row segment a NULL value will be returned, as there is no column before this one.

If the table is one-dimensional or if the expression is preceded by the total qualifier, the current row segment is always equal to the entire row.

If the pivot table has multiple horizontal dimensions, the current row segment will include only columns with the same values as the current column in all dimension rows except for the row showing the last horizontal dimension of the inter field sort order.

The inter field sort order for horizontal dimensions in pivot tables is defined simply by the order of the dimensions from top to bottom.

Specifying an offset greater than 1 lets you move the evaluation of expression to columns further to the left of the current column. A negative offset number will actually make the before function equivalent to a after function with the corresponding positive offset number. Specifying an offset of 0 will evaluate the expression on the current column. Recursive calls will return NULL.

By specifying a third parameter n greater than 1, the function will return not one but a range of n values, one for each of n table columns counting to the left from the original cell. In this form, the function can be used as an argument to any of the special range functions.

Examples:

before( sum( Sales ))

before( sum( Sales ), 2 )

before( total sum( Sales ))

rangeavg (before(sum(x),1,3))

returns an average of the three results of the sum(x) function evaluated in the three columns immediately to the left of the current column.



Not applicable
Author

Hi

Thanks for this, it has worked great and i now have a table with the values i want

One quick question though, when i go to Chart the values, i get nothing for the difference column, it says "no data to display"

Any ideas

Once again, thanks for the help