I am trying to calculate inventory turns (((this week inventory+ last week inventory)/2)/sales). To calculate the inventory I am using the previous(inventory) function so that I get the last week Inventory. But the issue is I have many dimensions where I will be using apart from the week dimesion. for ex: dept, store, and few more. issue is with sorting of previous(inventory) it is no where related .
What would be the expected result for your sample data?
In general, if you want to use Previous() / Peek() in the script, you need to order your data records accordingly and then you might need to check for changes in column segments (i,e, changes in Dimension values other than week number).
If you need to be dynamic with your inventory calculation (i.e. you can't calculate it in the script because it depends on selections / changing dimensions), you can use Above() chart inter record function, analog to Peek() in the script.