# Calculation Functions

**URL:** <https://pug.phocassoftware.com/t/calculation-functions/2009>\
**Category:** Ask the Community\
**Tags:** financial-statements\
**Created:** [October 19, 2021, 5:34pm UTC](https://pug.phocassoftware.com/t/calculation-functions/2009 "2021-10-19T17:34:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kai](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kai](https://pug.phocassoftware.com/u/kai)\
**Post date:** [October 19, 2021, 5:34pm UTC](https://pug.phocassoftware.com/t/calculation-functions/2009/1 "2021-10-19T17:34:50Z")

</div>

Hi,

Is there a way to use ‘CASE WHEN’ statements and other more complex methods in the calculation fields?

Right no my Gross Profit % for one month is NaN as the last month’s revenue has not been included yet (is 0). This causes the graph of Gross Profit % to not show up at all.

---

<div class="post-metadata">

**Author:** ![JonKemp](https://sea1.discourse-cdn.com/flex015/user_avatar/pug.phocassoftware.com/jonkemp/32/334_2.png) [@JonKemp](https://pug.phocassoftware.com/u/JonKemp)\
**Post date:** [October 20, 2021, 7:16am UTC](https://pug.phocassoftware.com/t/calculation-functions/2009/2 "2021-10-20T07:16:12Z")

</div>

Hi @kai,  
A few options at your disposal.

1. Can it be done as an calculated measure in the DB designer?  
This is mine:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/2X/2/284d01f46e7eb3b9b3243ca8ee8f9a44426f0fca.png)
2. Can you use custom mode to produce the same output?  
Like this:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/2X/5/5f04503a799f967271c196ea1f322a5aacdbd616.png)
3. What if I need to calc on a number that changes?  
This is the use case where static calcs like the above are not acceptable, so you are after if the value is over 50 then do this, else do that. This can be achieved in custom mode by a means of SQL commands. I must stress the case statement approach here will only deal with the numerical result for inspection, i.e. the case will **not** work on the dimension name so case = ‘Fred’ will **NOT** work but Case \> 50 **WILL** work. here is a detailed write up I did a year or so ago: [Percentage share in Custom Mode](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457)  
Hope this helps,  
Jon

---

<div class="post-metadata">

**Author:** ![AGonciulea](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@AGonciulea](https://pug.phocassoftware.com/u/AGonciulea)\
**Post date:** [October 21, 2021, 5:00am UTC](https://pug.phocassoftware.com/t/calculation-functions/2009/3 "2021-10-21T05:00:28Z")

</div>

Hi @kai

If the case statement has too many variables, it might be easier to do it in Sql. I usually do my case statements and Sql it’s easier to manage.

When it come to calculation Phocus does a great job but it all depends on how complex your calculations are.
