Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Calculate balance between income and expense

Avatar

Level 1

Hi, my problem is explained in below image. How to perform calculations which will include the result from previous row in the next. Etc.

Can you help with this. I can attach a form if needed.

Thank you

Picture6.png

1 Accepted Solution

Avatar

Correct answer by
Level 10

Using FormCalc language will make it easier...

In your balance field you should check if its index is higher than 0, if it is, then you should use the Balance before itself and add it to the current balance.

if ($.parent.index > 0) then

     $.rawValue = Income - Expense + $.resolveNode(Concat("Table1.Row1[", $.parent.index - 1,"]")).Balance

else

     $.rawValue = Income - Expense

endif

It should be something like this... change the names to use the right reference_syntax

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Using FormCalc language will make it easier...

In your balance field you should check if its index is higher than 0, if it is, then you should use the Balance before itself and add it to the current balance.

if ($.parent.index > 0) then

     $.rawValue = Income - Expense + $.resolveNode(Concat("Table1.Row1[", $.parent.index - 1,"]")).Balance

else

     $.rawValue = Income - Expense

endif

It should be something like this... change the names to use the right reference_syntax

Avatar

Level 1

Thanks Magus069, it is easier in FormCalc and I didn't know that.

I have one question about code: ", $.parent.index - 1," - commas after and before Quotation marks are part of the syntax?

Avatar

Level 10

Yes, the Concat method in FormCalc is taking any value, converting the value into string and concats all the values together...

If you seperate the values you concat these:

Which should result in any of the rows you have in the form

if $.parent.index -1 is returning the right number, your Field is inside the row directly you only need 1 parent to reach the Row1

if $.parent.index -1 is not returning the right number, check in your hierarchy, your Field should be inside a form, which the form is directly in the row, so you would need 2 parent to reach your Row1

$.parent.index - 1          or

$.parent.parent.index - 1


Avatar

Level 1

Thank you! Very good explained!