Display zero if calculation field results in null

I have tried everything without success to get a calculation field to display a zero if it results in null.
The code below works (as with many other possibilities) but only when I open the field and resave it - otherwise it remains empty. Can anyone explain why the calculation field is not responsive - is it a bug?

Screenshot 2025-05-06 at 15.38.40

@Leo Could you take look please?

Access to example case

Screen video - Tape

Hi Richard,
Have you tried this to solve your “open and resave in calculation field” [DONE] Calculation not displaying properly until first field is populated - #3 by Tim ?

I am not sure I understood your problem correctly in general, so sorry if this misses it massively. But maybe simply adding this “@Record ID” helps you.

Then, I think your video can only be seen by you, so I am not sure others are able to see it. If you want you can try the link in a private tab to check it.

I hope this helps.
Best,
R.J.

OK, thanks. I will take a look at your suggestions a bit later and let you know.

1 Like

OK, I have understood that its not a bug and is intention that the field remains empty if there is no value. Still haven’t worked out how to use use @RecordID to get the calculation to display a zero instead of an empty field

@RichardHedger

I have a horrid feeling that I am missing what you are saying/trying to do however:

@Sum of Numberï»ż ? ï»ż@Sum of Numberï»ż : 0;

gives me a zero if there is nothing there?

1 Like

Hi Richard,
What is being displayed after including this @Record ID? I am not sure I understand this correctly.

Best,
R.J.

In fact this issue has already been raised and clarified by Leo. I have a calculation field (App A) that sums the amounts of a field in record in a related app (App B). However, when the record in App B does not exist yet, the calculation field in App A (that has just been created) produces no result and remains empty I want the calculation field in App A to display a zero in this case. Hope that was clearer. I’m not sure that there is a solution for this .

This should work for you.

Let montant = @Sum of Montant payé || 0;

montant;

Thanks but it doesn’t solve my problem. Perhaps my screenshots below clarify what I see.
Record 2 in App B has no value (not even null) as I have understood Leo’s comment : 'Currently by design calculations will only calculate for a new record when the referenced fields (inside the calculation script) have a value.


The workaround is to create a a related record in App A with no value. This allows the record in App B to trigger the calculation for the first time. Is there a more elegant way of achieving this.

The record in App A can also be deleted but the record in App B remains zero.


.

My use case:

In App A I have a list of payments
In App B I have a list of invoices.

In another app I have a contract which contains a calculation field that summarizes in a table all related invoices with the values of their respective payments. However, if there is no payment value yet for a given invoice, then the invoice with no payment value does not display.

Thanks to everyone’s comments - I’m new to Tape so its much appreciated.

1 Like

I think I understand now.
Do me a favor and try to call any other field from inside of your item at the top.

Add

Let foo = @anyItemField;
Let montant = @Sum of Montant payé || 0;

montant || 0;
1 Like

or this (I’m on my phone so check me)

Let foo = anyItemField;
Let montant = 0;

If (@Sum of Montant payé != null) { montant = @Sum of Montant payé;
}

Montant;
1 Like

Yep, that worked - thanks.

This works too. So the conclusion is that calling any other field at the beginning triggers the first calculation and provides any value than can be change immediately.

Exactly. Something needs to be in the calculation in order for it to run. Then we set any null value to default to 0 when empty.

I’m glad that worked for you.

Sometimes you’ll need to force the value to become a number so you can set the calc style to ‘number’ instead of text.

1 Like