theyetti Posted February 9, 2007 Posted February 9, 2007 (edited) Hi All, is it possible to calculate the average price from the last three purchase orders for a stock item? I'm just not sure how to obtain and evaluate just the last three prices. Additionally some low use items may only have one price recorded for that item which makes it a bit harder. Thanks Peter :-) Edited February 9, 2007 by Guest
mr_vodka Posted February 9, 2007 Posted February 9, 2007 Well if your PO has a related line items table between the products and the PO, you can from the products side make a relationship sorted by date Descending. Then you can use an Unstored calc of: cLastThree [repeating calc of 3 reps] = GetNthRecord ( Extend ( ProducttoLineItem::price ); Get ( CalculationRepetitionNumber ) ) ProdAvg = Average ( cLastThree ) In regards to what you mentioned as "low use items" having only one price, it is okay because an average of only one number is the number.
comment Posted February 9, 2007 Posted February 9, 2007 You could just as easily get them from the other end (i.e. without forced sorting): Let ( [ n = 3 ; m = Count ( Child::ParentID ) ; i = Get ( CalculationRepetitionNumber ) ] ; Case ( i ≤ Min ( 3 ; m) ; GetNthRecord ( Extend ( Child::Value ) ; m - i + 1 ) ) )
theyetti Posted February 10, 2007 Author Posted February 10, 2007 (edited) Thanks for the ideas, I'll try them and see how I go. The individual purchase order line items use the StockID as a secondary key so are related to the Stock Items. Thanks Peter :-) Edited February 10, 2007 by Guest
theyetti Posted February 10, 2007 Author Posted February 10, 2007 (edited) Hi Comment, I've tried using your suggestion but it seems to only evaluate the last P/O Line Item record created for each stock item? I've tried to figure out why this is but I'm not very familiar with some of the functions used. Could you post a small explanation about each step so I can learn from this? Thanks Peter :-) Edited February 10, 2007 by Guest
comment Posted February 10, 2007 Posted February 10, 2007 Here's a working demo, with comments added to the calculation. AverageLastN.fp7.zip
theyetti Posted February 10, 2007 Author Posted February 10, 2007 Many Thanks Comment, it turned out that I only had one repetition specified on the main calculation field so it only showed the most recent value. Cheers Peter :-)
Recommended Posts
This topic is 6557 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now