Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using Previous in formula

Status
Not open for further replies.

JasonKaufman

Programmer
Apr 13, 2006
46
US
I am using the following formula for all sales orders within a group of the same item number (for all item numbers) and am wanting to take the OnHand qty minus each individual Sales Order Qty and then take that total and use it for the next sales order # qty.

This formula seems to work for the first and 2nd sales order #, but fails afterwards.

if previousisnull ({SO2_SOEntryDetailLine.ItemNumber}) then
{IM2_InventoryItemWhseDetl.QtyOnHand} - {SO2_SOEntryDetailLine.QtyOrdered}
else
if {SO2_SOEntryDetailLine.ItemNumber} = previous ({SO2_SOEntryDetailLine.ItemNumber})
then
{IM2_InventoryItemWhseDetl.QtyOnHand} - previous ({SO2_SOEntryDetailLine.QtyOrdered}) - {SO2_SOEntryDetailLine.QtyOrdered}
else
{IM2_InventoryItemWhseDetl.QtyOnHand} - {SO2_SOEntryDetailLine.QtyOrdered}

I know there has got to be a better way to write this as well as making it work, but at the moment i am stymied.

Any help would be greatly appreciated.
 
Try:

whileprintingrecords;
nunmbervar onhand;
if onfirstrecord then
onhand:={IM2_InventoryItemWhseDetl.QtyOnHand} - {SO2_SOEntryDetailLine.QtyOrdered}
else
if {SO2_SOEntryDetailLine.ItemNumber} = previous ({SO2_SOEntryDetailLine.ItemNumber})
then
onhand:= OnHand - previous ({SO2_SOEntryDetailLine.QtyOrdered});
onhand

The downside of this is that you never seem to have any new inventory, it's just constantly subtracting from it, which seems very odd...

Also it's an infinitely better idea to show us example data and expected output than a non-functioning formula. Add to that your software versiona nd the database and you'll provide a reasonable environment and requirement.

If you feel it required afetrwards, then show bad formulas and chat about what you think might or might not work.

-k
 
Sorry i didnt give u as much info as i should have.

I use CR 8.5 for Mas200

as far as the inventory only subtracting, i knew that once i got this initial hurdle crossed, then i would be able to add PO qty to this formula and have it give a true day by day accounting of inventory.

I modified your formula since when i initially employed it, it didnt quite work, but I was able to play with it a bit and got it working by using

whileprintingrecords;
numbervar onhand;
if previousisnull ({SO2_SOEntryDetailLine.ItemNumber}) then
onhand := {IM2_InventoryItemWhseDetl.QtyOnHand} - {SO2_SOEntryDetailLine.QtyOrdered}
else
if {SO2_SOEntryDetailLine.ItemNumber} <> previous ({SO2_SOEntryDetailLine.ItemNumber})
then onhand := {IM2_InventoryItemWhseDetl.QtyOnHand} - {SO2_SOEntryDetailLine.QtyOrdered}
else
if {SO2_SOEntryDetailLine.ItemNumber} = previous ({SO2_SOEntryDetailLine.ItemNumber})
then onhand:= onhand - ({SO2_SOEntryDetailLine.QtyOrdered})

thanks for your help in this matter and i will endeavor next to include software/database/data info.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top