Search code examples
jsonformula

How to write a json formula


I am writing a json formula to calculate a custom value, need it to look like this:(last_price - cost) / last_price * 100. I am a little confused on where to put left and right parts of the calculation, like what should go first - "100" or "/last_price"

I wrote this, which makes it into (last_price-cost)*100 I guess:

"formula": {
   "operation": "*",
    "left": {
     "operation": "-",
     "left": {
     "operation": "value",
      "type": "custom_fields",
      "value": "last_price"
  },
  "right": {
    "operation": "value",
    "type": "custom_fields",
    "value": "cost"
  }
  },
  "right":{
    "operation": "value",
    "type": "const",
    "field": 100

Solution

  • Friend recommended to change formula to (1 - cost / last_price) * 100, which makes it much easier for me to put into.