How to make a variable sum ?

Hello,

I’m on Microsoft Dynamics NAV 2013 ans i want to make a sum of variable.

I had try to make this with C/AL. But it doesn’t worked.

My Code :

MontantHT := Quantity * “Unit Price”;

TotalHT += MontantHT; ( This line doesn’t Work )

NetHT := TotalHT - “Line Discount Amount”;

TVA := “VAT %” * NetHT;

Thanks in advance

ps : I had try CurrReport.CreateTotals() but it doesn’t worked

Where did you write above code and what do you mean by not working?

Is it showing 0 only or wring total?

What did you write in visual studio?

Hello, thanks for replay.

I had write this code in the “OnAfterGetRecord” section.

In visual studio i had set the value to " =Fields!TotalHT.Value"

And when i run the report there is " 0 "

Did you check the value in Dataset result? i.e., About This report?

http://mibuso.com/blogs/mohana/2012/01/11/how-to-see-dataset-result-in-rtc-reports/

I’m sorry, it’s not write 0. It’s just have the “MontantHT” about the first line. There is not the second, the sum doesn"t work.

My About Page :

To help you, i want to make the sum of (187.1+346.3) and it only make the sum of the first line (187.1

)

Please follow my blog carefully.

You have pressed About this Page at wrong place…

Ohh sorry. The values on the TotalHT column are " 0 ". I have three rows (Ok compare to the invoice sale)

Write a message in your code and check what you are getting while running

MontantHT := Quantity * “Unit Price”;

TotalHT += MontantHT; ( This line doesn’t Work )

Message(’%1’,TotalHT);

NetHT := TotalHT - “Line Discount Amount”;

TVA := “VAT %” * NetHT;

Did you try by adding “=SUM(Fields!MontantHT.Value)” in visual studio?

My problem is solved ! Thanks to your blog post !

I have tried “=SUM(Fields!MontantHT.Value)” yesterday and it works but i don’t want to make in this way.

I want to have variable to reduce code in expression value. I reuses formulas and end it there’s a huge line that’s why i prefere variable :slight_smile:

Solution :

C/AL ==> TotalHT += MontantHT;

Visual Studio Expression value : Last(Fields!TotalHT.Value)