How to use computed field in Microsoft Ligthswitch?

Below is an example of a computed field in action.  I use this to compute for the balance of a loan from a financing company.  A single loan amount (SI Amount) has multiple adjustments through Credit / Debit Memo records and multiple payments through collection records (OR Amount).

The first step in creating a computed field is to open the EF table design and add a Computed Property (#1 in the screen below).  Every time you add a computed property it will insert a field into your EF table with a calculator icon in the left side (#2 in the screen below).  And the last step is to provide the computation of each field, to do that just click any calculated field and click the Edit Method link in the right side property box (#3 in the screen below).

The code is very simple, just compute for a value to the result (return) variable provided by the method (see sample code below).  Thats it.

Private Sub BalanceAmountComputation_Compute(ByRef result As Decimal)
   'Set result to the desired field value
   result = IIf(IsNothing(Me.SIAmount), 0, Me.SIAmount) + _
            IIf(IsNothing(Me.DMAmountComputation), 0, Me.DMAmountComputation) - _
            IIf(IsNothing(Me.CMAmountComputation), 0, Me.CMAmountComputation) - _
            IIf(IsNothing(Me.ORAmountComputation), 0, Me.ORAmountComputation)
End Sub

Software developer living in the Philippines.

Posted in Lightswitch

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Harold Glenn P. Minerva
Software Developer / Tech Enthusiast
Living in the Philippines

View Harold Glenn Minerva's profile on LinkedIn


Software Engineer - Seasonal and Range Trading Software. Magenta Trader is a powerful stock market visualization software that increases your probability of trading success.

Software Architect and Founder - is a multi-tenant cloud-based Software-as-a-Service (SaaS) business app that caters to micro, small and medium trading businesses.

CTO and Co-Founder - We give your company the leverage by providing innovative software solutions products such as Point-of-Sales (POS), Financial Information System (FMIS), Payroll and DTR (HRIS), and many more.

%d bloggers like this: