Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Performing Mathematical Calculations in Business Central Visual Studio Code

(0) ShareShare
ReportReport
Posted on by 181

Hey Everyone.

I have created a hypothetical task in which I am trying to perform a mathematical calculation in Business Central and record the output values in a subledger account. An example of the calculation is 

Interest on Savings =  $50 * 0.047 (interest rate) * 31/365 (number of days in a month divide by number of days in a year) = $0.20

I have done a similar calculation when i wrote a C++ code in which I would write a procedure and call that procedure to perform the calculation but how can i accomplish something similar in Visual Studio Code in Business Central. I know that I can use CodeUnit which is similar to a procedure I believe in C++ but my worry is how do I record the output into a GL account? Any thoughts would be nice or any experience with writing a similar code with mathematical calculation would also be appreciated. 

  • Suggested answer
    THE Italian Profile Picture
    on at
    RE: Performing Mathematical Calculations in Business Central Visual Studio Code

    Yes. This can be done. You could create create field A and field B where you gather values and then field C is enabled=false and just trigger the result of the formula after validation of the fields

  • Aneeq Profile Picture
    181 on at
    RE: Performing Mathematical Calculations in Business Central Visual Studio Code

    what if i have different scenarios that determines how the calculation will be done? I am thinking if I should ask the user to input certain fields in the payment journal and use IF THEN statements to figure out which calculation to perform. Will I have to create an extension by adding fields to payment journal and referencing the codeunit to those field? Can that happen?

  • attique Profile Picture
    10 on at
    RE: Performing Mathematical Calculations in Business Central Visual Studio Code

    I am wondering if you can add an extension (field) to the payment journal and let the user enter some values and let the system output the correct interest value. Do you think that is a good option for you and practicable?

  • Suggested answer
    THE Italian Profile Picture
    on at
    RE: Performing Mathematical Calculations in Business Central Visual Studio Code

    You have to create a function inside a codeunt where you pass the parameters you need. 

    Every time you need that calculation, you have to reference that codunit into your object and call the function where you need most. 

  • Suggested answer
    keoma Profile Picture
    32,727 on at
    RE: Performing Mathematical Calculations in Business Central Visual Studio Code

    you can write the formula like in c++.

    to add the result to a g/l account you have to create a g/l entry.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 815

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 1

#3
Mansi Soni Profile Picture

Mansi Soni 559

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans