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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Subtraction of two columns

I have a Straight Table which displays current and previous stock for every Product with its location. Item and Location are dimensions and Current stock and Previous Stock are expressions based on the input dates by the user.

Prod Loc Current Stock   Previous Stock

1      A    10,000             -  

1      B                           20,000

1      B     15,000

2     A    7,000             -  

2     B                           12,000

2     B     10,000

Now I want to display the table with difference stock (Current Stock - Previous Stock) for the respective Product and location. Like this:

Prod Loc Current Stock   Previous Stock    Difference Stock

1      A    10,000             -  

1      B                           20,000               

1      B     15,000                                      -5000

2     A      7,000             -  

2     B                           12,000                

2     B     10,000                                       -2000

Any suggestions would be appreciated.

Thanks a lot!!!

8 Replies
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Generally speaking, you need to look at functions like above() or before() to do something like this.

I'm wondering, however, how can you get two separate rows for the same Product and Location, where one row only shows Current Stock and the other row only shows Previous Stock?

If you used aggregation functions like sum(), min(), etc... , you would get a single row with both numbers filled out. To get two separate rows, you must be using hidden dimensions, or not using aggregation in your expressions.

My point is - if you don't need to split your presentation into two separate rows, then your calculation could be much simpler...

Ask me about Qlik Sense Expert Class!
Clever_Anjos
Employee
Employee

Try to use above() function to get last row value

Not applicable
Author

If your data is shown in QlikView as your example, I suggest you do a group by Prod and Loc and then you can get the difference using a preceding load or in the straight table.

I suggest the next:

LOAD

          *,

          [Current Stock] - [Previous Stock] as [Difference Stock];

LOAD Prod,

          Loc,

          sum([Current Stock]) as [Current Stock],

          sum([Previous Stock]) as [Previous Stock]

FROM

whatever your source

GROUP BY Prod, Loc;

Hope it helps!

Not applicable
Author

Thanks Oleg! I am trying to put all data in one row.

Not applicable
Author

Thanks Carlos and Clever for your response but now I m trying to put data in one row.

Not applicable
Author

Thanks Carlos and Clever for your response but now I m trying to put data in one row.

Not applicable
Author

Ok, My suggestion also puts all data in one row. In fact it's just what Oleg's answered but with the script part. Give it a try.

Not applicable
Author

Sure Carlos I'll try that, once again thanks a lot!!