Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!!!
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...
Try to use above() function to get last row value
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!
Thanks Oleg! I am trying to put all data in one row.
Thanks Carlos and Clever for your response but now I m trying to put data in one row.
Thanks Carlos and Clever for your response but now I m trying to put data in one row.
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.
Sure Carlos I'll try that, once again thanks a lot!!