Substraction of next amount from previous amount.
Freaky
Member Posts: 125
Hi Guys, can anyone help me on how I can get the differences between amounts.For example I have a variable called
amount
56
86
so i will like to have an answer of 86-56=30.
Thanks in advance.
amount
56
86
so i will like to have an answer of 86-56=30.
Thanks in advance.
0
Comments
-
perhaps try giving your variable dimensions and make an array - then you'd have to add code to move the value of amount[1] to amount [2] on each iteration and then you could subtract [1] from [2]... does that get you started?kind of fell into this...0
-
Jversusj thanks for the help but I have no idea on how to use arrays in Nav. And my values on the variable "amount" is not just two they are numerous. Can you please assist more.0
-
-
Am Sorry if I did not give you a clear picture of what I meant this is how it is
Amount(decimal)
56.00
86.00
86.00
357.00
389.00
413.00
480.00
it continues
Results
0
86-56
86-86
357-86
389-357
413-357
480-413
it continues
So in each case I want to subtract the first value from the second value.
Thanks.0 -
i think you can do this, like i said, with an array.
create your variable and look at the properties. Set the dimensions property to 2 - this will let you keep 2 values in the variable at a time: variable[1] and varibable [2]. then you would do your processing. on your first record (you could be clever to code for the first time it happens versus all subsequent times), you would set variable[2] = your value. variable[1] would be 0. you could then do variable[2] - variable[1].
for all subsequent records you would first say variable[1] := variable[2], then you would set variable[2] equal your new value. you could then do variable[2] - variable[1] as before and get the difference.
so, using your example values:
56.00
86.00
86.00
357.00
389.00
413.00
480.00
etc.
the first time through, set variable[2] := 56.00. there is no previous entry because you just started, so difference := variable[2] - variable[1] would be 56.00. you could code a different formula if you really want the answer to be 0 (according to your example).
the next record would set variable[1] := 56.00 and variable[2] := 86.00, then difference := variable[2] - variable[1].
you would continue this through all records and always subtract the current from the previous.kind of fell into this...0 -
If it's on a form, then you could do the following :
- Add a Global Variable for your difference ( I'l call it Difference )
- Add a textbox to your tablebox, and add the Difference variable as its SourceExpression
- In the OnAfterGetRecord of the form, declare a variable of the same type as the main record ( let's call it PrevRec )Prevrec.copy(rec) ; if PrevRec.next(-1) <> 0 then //No previous Record found, assume 0 as previous value PrevRec.init ; Difference := Rec.Value - Prevrec.value ;
Oh, and do consider that this will look strange if the records aren't sorted on the value you want to use, and filters might do strange things.0 -
boolfirst := true repeat actualvalue = tb.amount if BOOLfirst then begin BOOLfirst := false; result := 0; end else begin result := actualvalue - previousvalue; end; previousvalue := tb.amount; until tb.next = 0;
***Not tested but should work
0 -
Thanks guys for the help. I finally succeeded by using the array method jversusj posted.0
-
good to hear, although you should note that belias' code does the same thing, without messing with arrays. you would just set up two variables instead of 1 variable with multiple dimensions.kind of fell into this...0
-
but at least he learnt arrays...which is good!jversusj wrote:good to hear, although you should note that belias' code does the same thing, without messing with arrays. you would just set up two variables instead of 1 variable with multiple dimensions.
0 -
Belias I try using your code and when I try compiling it, it says THERE IS A SYNTAX ERROR.
Thanks0 -
Come on! don't blame me so much!Freaky wrote:Belias I try using your code and when I try compiling it, it says THERE IS A SYNTAX ERROR.
Thanks
(joking)...i forgot a semicolon...hmmm 2 semicolon, 1st and 3rd line...i didn't compile the code pefore posting it... 8)
....and put a findset or find('-') before the repeat :whistle:0 -
Thanks once more. 0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

