# Calculations (formula) - help needed

Hi,
please, can anyone here help me to set up properly some calculation fields (formula) in my table?

Let’s say I have a table with student’s names where one of my columns (fields) is a number type, where I put manually the year, when student finished his exam (or let’s say he finished the high scool). I will name this field as “EXAM”.

I would like to create two more fields:
One field - I will call it “CALC”- auto-calculated, where number 25 is subtracted from the “EXAM” field and result is displayed here.
And then another field (I will call it “CALC2”), which will use actual year as an input number (so just now it would be a number 2023, but next year it will be number 2024) and then the number from “CALC” field will be substracted from it and will display the result number.

Example:
if I will put the number 2015 in the “EXAM” field, then in “CALC” field I should see the number 1990 and in “CALC2” field I should see the number 33.

One more thing: if the “EXAM” field is empty, then no calculations should be done.

Thanks!

Hello @marcus, here you are: Grid // Baserow.

Field CALC: formula `field('Exam') - 25`
Field CALC2: formula `year(now()) - field('CALC')`

Hope it helps Great, works. Thanks for it.
Just one more thing: how can I add the exception to CALC anc CALC2 fields? I mean, if EXAM field is empty, then also fields CALC and CALC2 should be empty too.

Hey, you can achieve that by using functions `if` and `is_null`, here’s how it works: Grid // Baserow.

Field CALC: `if(is_null(field('Exam')), '', field('Exam') - 25 )`
Field CALC2: `if(is_null(field('Exam')), '', year(now()) - field('CALC'))`

Hi Olga, wonderful, thanks for your help.

First formula works correctly, but second formula

``````if(is_null(field('Exam')), '', year(now()) - field('CALC'))
``````

which is for field CALC2 - - gives me this error: Error with formula: argument number 2 given to operator - was of type text but the only usable type for this argument is number.
It looks like the problem is that field CALC is formula type, but formula function expects (requires) standard number filed type. It’s silly, but if it’s like that, then I need some workaround for it.
Ahhh, I see!!! I need to keep those first created fields with formulas too and then add two more with those new formulas with exception Glad to hear you figured that out!
{"ft_lang_label":"__label__en","ft_lang_prob":0.9248252,"math_prob":0.8087491,"size":1036,"snap":"2023-40-2023-50","text_gpt3_token_len":271,"char_repetition_ratio":0.16472869,"word_repetition_ratio":0.020942409,"special_character_ratio":0.26061776,"punctuation_ratio":0.09174312,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9947735,"pos_list":[0,1,2,3,4,5,6,7,8],"im_url_duplicate_count":[null,8,null,4,null,1,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-29T19:30:06Z\",\"WARC-Record-ID\":\"<urn:uuid:fbe71a32-ebde-43c5-ad3d-80f73ab89f21>\",\"Content-Length\":\"29590\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8a9a1e3e-6b7b-4ef1-af02-8d9fe0e205b9>\",\"WARC-Concurrent-To\":\"<urn:uuid:b06e96f5-4a66-413a-8134-50c193c6bf9b>\",\"WARC-IP-Address\":\"64.225.74.106\",\"WARC-Target-URI\":\"https://community.baserow.io/t/calculations-formula-help-needed/3200\",\"WARC-Payload-Digest\":\"sha1:XGKDWNTGKBBX6W3EFJYWCI257EBQXWME\",\"WARC-Block-Digest\":\"sha1:375CTRCYHRD3MTDW7GMQUA6QJKKJSXBH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510528.86_warc_CC-MAIN-20230929190403-20230929220403-00197.warc.gz\"}"}