Hello!
I want to calculate the total sum “on the fly” each time a new row is added to the table (in the add form). For example, I create a new Order and immediately add a list of products to the subtable, where there is Price, Quantity, and Sum. And I want to immediately see the total sum for all Products (i.e., the sum in the Sum field).
How can I do this so that I can see the change in the total Sum in the Order in real time (as in the Google Sheets screenshot below, for example)?
I know that, in general, the total Sum can be calculated using a workflow, but I will only see the result after saving the current order record. And I need the result to be displayed as soon as the Product rows are filled in.
Is there any way to implement this functionality? Has anyone had a similar case?
Hi
I found similar case in nocobase CRM.
Exsamples > Linkage Rules
Total Price — calculate in Linkage Rules
SubTotal — calculate in Fields Linkage Rules
Is it Helpful?
2 Likes
@tomix-jp Thank you for the interesting tip! It’s a very practical solution, I’ll try to implement the functionality according to your method!
Please tell me how you managed to create Linkage Rules within a sub-table (calculation for the Total Price field)? I can’t seem to “get” from editing the current record into the sub-table row. This is because there can be many rows.
There are Field Linkage Rules, but they only work with the fields of the editable (parent) record, and the sub-table fields are not displayed…
I found it)) Strange that I didn’t notice it right away))
@tomix-jp Please tell me, is it possible to calculate the totals, but not for all records, only for certain ones?
For example, there is an Order and a Service Block in Order. The Service Block collection has a Category field (a field associated with the Product Categories collection).
I want to calculate the sum in the Order for the Service Block collection in Order, where the Service Block is assigned the Category “Transportation” (let’s say, in the Product Categories collection, its ID = 342601866543104).
That is, a very rough example of a query should be something like this:
SUMIF([Order / Service Block in Order / Price], “Order / Service Block in Order / Category / ID = 342601866543104”)
Below is a screenshot of an attempt to create an expression for calculation (some of the information is in Russian, but I think the essence will be clear).
I can’t create a condition like “Order / Service Block in Order / Category / ID = 342601866543104” because this expression must somehow select records from the array/subset of Service Block collection.
Is there a solution to put the condition in the expression itself for selecting records and calculating the value?
I think you’ll have to write custom code in a JS field
Yes, I understand that, but the whole point is to do it “with no-code.” With JS code, you can create any logic, interfaces, etc. The main thing is to know how to code. 
In addition, my task is to form an expression in a field on the Classic Page (version 1), and JS blocks are supported on the Modern Page (version 2)… I am not using version 2 yet because it does not have full functionality yet. I am waiting for a more complete version, at least with the same features as version 1 (or close to it).
I see a potential issue with your sumif. It put quote around the id. Last time I checked, id are integer.
And second, if you see an iframe option (it’s usually there with markdown), we still have a last resort for coding on V1 page.
I tried many different ways of writing the expression syntax in this function (on the page Formula.js - NocoBase Documentation).
But there is still no result.
I’m not quite sure how this will help me… I need the result of the expression to be placed in the input field (the “Value” option). I’m not an experienced specialist yet, so if you have more detailed instructions on how to do this using iframe (or Markdown), I would appreciate your help!
I meant that, you should remove the quote around the id since if you put it, it’ll think that the ID is a string (it’s not, it’s an integer)
So maybe something like this.
SUMIF(… = 342601866543104)
And if you need it to be in the input field, then my iframe suggestion won’t work. (But in page V2, you can)
If my no quote technique don’t work, you can try adding a formula field instead of a number field as the subtotal. There, you can use a different formula engine (and maybe it’ll work)
1 Like
If none of this work and you decided to choose page V2, just ask me. It’s an easy code for me.
And also did you know that you can turn on browser notification for this platform? It’ll help with communication.
1 Like