{
  "id": "N3tA1txoSK9BM5HD",
  "name": "Markup/Profit Margin Calculator",
  "tags": [],
  "nodes": [
    {
      "id": "9733ae36-a825-4bb5-9ef7-402273471799",
      "name": "On form submission1",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -1792,
        624
      ],
      "parameters": {
        "options": {
          "ignoreBots": true
        },
        "formTitle": "Profit Margin and Markup Calculator",
        "formFields": {
          "values": [
            {
              "fieldType": "number",
              "fieldLabel": "Products cost",
              "placeholder": "How much does your product cost",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Tax",
              "placeholder": "Tax percentage of your final price",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Fee percentage",
              "placeholder": "Fee percentage for marketplace",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Profit Margin or Markup",
              "placeholder": "Desired value (%)",
              "requiredField": true
            },
            {
              "fieldType": "radio",
              "fieldLabel": "Calculation Method",
              "defaultValue": "Profit Margin",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Profit Margin"
                  },
                  {
                    "option": "Markup"
                  }
                ]
              },
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5b02ce60-6c03-4a8a-b59b-7fac3f68e68f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2432,
        192
      ],
      "parameters": {
        "width": 528,
        "height": 1312,
        "content": "## \ud83d\udcd8 Workflow Overview\n\n### What this workflow does\n\nThis workflow provides a web form that calculates the selling price of a product using either a desired **Profit Margin** or **Markup**.\n\nAfter submitting the form, users receive:\n\n- Selling Price\n- Profit\n- Profit Margin\n- Markup\n\nThe workflow also validates user input and displays an error message when the entered values are mathematically invalid.\n\n---\n\n### Setup\n\n1. Activate the workflow.\n2. Open the **On form submission** node.\n3. Copy its **Production URL**.\n4. Paste the URL into the **Set URL** node, replacing `REPLACE_WITH_PRODUCTION_FORM_URL`, so the **Calculate Again** button redirects back to the input form.\n\n---\n\n### Calculation Methods\n\n**Profit Margin**\n\nCalculates the selling price required to achieve a desired profit margin after taxes and fees.\n\nValidation:\n- Tax + Fee + Profit Margin must be less than 100%.\n\n**Markup**\n\nCalculates the selling price using the desired markup percentage over the product cost.\n\nValidation:\n- Markup must be greater than or equal to 0%.\n\n---\n\n### Customization\n\nYou can customize:\n\n- Currency formatting\n- Pricing formulas\n- Form labels\n- Validation rules\n- Styling (CSS)\n\nThe calculation logic is located in the \"**Calculate - Profit Margin**\" and \"**Calculate - Markup**\" Code nodes."
      },
      "typeVersion": 1
    },
    {
      "id": "2d908132-e075-40a2-be33-bb0699fb43dd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        64
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 272,
        "content": "## Show results for Profit Margin"
      },
      "typeVersion": 1
    },
    {
      "id": "c78caffa-afb3-4439-a9a5-3fc55bcf4c43",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1856,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 224,
        "height": 272,
        "content": "## Initial page"
      },
      "typeVersion": 1
    },
    {
      "id": "eb234928-0f71-489f-94b2-feb4b8bc3ae1",
      "name": "Set URL",
      "type": "n8n-nodes-base.set",
      "position": [
        -1552,
        624
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "4b878acc-8dd2-413e-b780-ad50fb3b33ad",
              "name": "url",
              "type": "string",
              "value": "REPLACE_WITH_PRODUCTION_FORM_URL"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "909ebdbe-fb19-45e7-8247-ddf7f381145a",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        -384,
        512
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Profit Margin",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "1b83e0d7-6759-497e-8095-e169e86cf6a5",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('On form submission1').item.json['Calculation Method'] }}",
                    "rightValue": "=Profit Margin"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Markup",
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d5eb80a1-3156-454e-ad47-4ac187e5ba18",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('On form submission1').item.json['Calculation Method'] }}",
                    "rightValue": "Markup"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    },
    {
      "id": "51642625-a115-48ac-bd3c-a18e40f301b0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        656
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 272,
        "content": "## Show results for Markup "
      },
      "typeVersion": 1
    },
    {
      "id": "7ad9ab2b-f843-46ca-8fc3-5fb0fc31ab62",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 1104,
        "content": "## Data validation 2\n\nFor profit margin calculations, the sum of Tax, Fee and Profit Margin must be less than 100%\n\nFor Markup calculations, Markup must be greater than or equal to 0%"
      },
      "typeVersion": 1
    },
    {
      "id": "23b44329-9c32-47ef-a440-2e464ec5210c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        336
      ],
      "parameters": {
        "color": 7,
        "width": 672,
        "height": 288,
        "content": "## Show an error for Profit Margin"
      },
      "typeVersion": 1
    },
    {
      "id": "2893d5d8-817f-4eca-818e-7cc16e6770d1",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        928
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 288,
        "content": "## Show an error for Markup"
      },
      "typeVersion": 1
    },
    {
      "id": "20e7a239-c92b-48b7-998f-05465c151e34",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1632,
        528
      ],
      "parameters": {
        "color": 7,
        "width": 224,
        "height": 272,
        "content": "## Set URL"
      },
      "typeVersion": 1
    },
    {
      "id": "fd5316c5-4f7d-42be-b11c-3cfaef67aa42",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        320
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 576,
        "content": "## Markup or profit margin?"
      },
      "typeVersion": 1
    },
    {
      "id": "60401a0f-e3a9-4f7e-b043-a28b454a6457",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1408,
        432
      ],
      "parameters": {
        "color": 7,
        "width": 912,
        "height": 656,
        "content": "## Data Validation\nProduct cost must be greater than 0. Tax and Fee must be greater than or equal to 0."
      },
      "typeVersion": 1
    },
    {
      "id": "6dff5999-ef4a-464e-b273-fdea8686f2ec",
      "name": "Check Product Cost",
      "type": "n8n-nodes-base.if",
      "position": [
        -1344,
        624
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "93a7eadc-e455-4bac-a02a-efba75063934",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('On form submission1').item.json['Products cost'] }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "202d4a8f-62bb-4cb5-a7b6-0c9923af5a04",
      "name": "Check Tax and Fee",
      "type": "n8n-nodes-base.if",
      "position": [
        -1136,
        528
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e8e20fc3-50a7-4918-91e9-eccdb4393118",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $('On form submission1').item.json.Tax }}",
              "rightValue": 0
            },
            {
              "id": "5ec4d647-2f1c-4408-a102-b317c73d6a78",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $('On form submission1').item.json['Fee percentage'] }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "73fdc20d-c5ab-4eb0-ba7d-287fbbbf2a93",
      "name": "Error Message about Cost",
      "type": "n8n-nodes-base.form",
      "position": [
        -1104,
        896
      ],
      "parameters": {
        "options": {
          "formTitle": "Results",
          "buttonLabel": "Finish",
          "formDescription": "=Your input is not valid! Product cost must be greater than 0."
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "bc16962a-5c11-4c62-9ab6-ee86dd395307",
      "name": "Error Message about Tax and Fee",
      "type": "n8n-nodes-base.form",
      "position": [
        -928,
        672
      ],
      "parameters": {
        "options": {
          "formTitle": "Results",
          "buttonLabel": "Finish",
          "formDescription": "=Your input is not valid! Tax and Fee must be greater than or equal to 0."
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b5cd0811-201f-43f4-9894-2104d7bcd9f4",
      "name": "Return to Initial Page1",
      "type": "n8n-nodes-base.form",
      "position": [
        -912,
        896
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "redirectUrl": "={{ $('Set URL').item.json.url }}",
        "respondWith": "redirect"
      },
      "typeVersion": 2.3
    },
    {
      "id": "35910a7f-72a3-46ea-ab25-71d85369dbf4",
      "name": "Return to Initial Page2",
      "type": "n8n-nodes-base.form",
      "position": [
        -720,
        672
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "redirectUrl": "={{ $('Set URL').item.json.url }}",
        "respondWith": "redirect"
      },
      "typeVersion": 2.3
    },
    {
      "id": "73b78962-4378-419c-a285-96bd3d1ffee7",
      "name": "Check Profit Margin",
      "type": "n8n-nodes-base.if",
      "position": [
        160,
        192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f522b68b-c53b-44f3-9b69-bb878a0c3438",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{1 - Number($('On form submission1').first().json.Tax) / 100 - $('On form submission1').item.json['Fee percentage']/100 - $('On form submission1').item.json['Profit Margin or Markup']/100}}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "71c38f5d-5f39-452c-b90b-e3b960f5d54a",
      "name": "Check Markup",
      "type": "n8n-nodes-base.if",
      "position": [
        176,
        768
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "2ef5eeb4-5b9b-4488-a90c-59571d45c910",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $('On form submission1').item.json['Profit Margin or Markup'] }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "e46d142e-b2c1-4523-8627-6ee7db833103",
      "name": "Error Message about Markup",
      "type": "n8n-nodes-base.form",
      "position": [
        544,
        1008
      ],
      "parameters": {
        "options": {
          "formTitle": "Results",
          "buttonLabel": "Finish",
          "formDescription": "=Your input is not valid! Markup must be greater than or equal to 0%."
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "875dc1e8-8c67-4047-95b5-367d542331b7",
      "name": "Return to Initial Page6",
      "type": "n8n-nodes-base.form",
      "position": [
        784,
        1008
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "redirectUrl": "={{ $('Set URL').item.json.url }}",
        "respondWith": "redirect"
      },
      "typeVersion": 2.3
    },
    {
      "id": "b7af8826-b917-4a11-b6da-70566c823b08",
      "name": "Return to Initial Page5",
      "type": "n8n-nodes-base.form",
      "position": [
        1024,
        752
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "redirectUrl": "={{ $('Set URL').item.json.url }}",
        "respondWith": "redirect"
      },
      "typeVersion": 2.3
    },
    {
      "id": "6b60d038-a342-4c88-8a83-0044adcb6885",
      "name": "Return to Initial Page4",
      "type": "n8n-nodes-base.form",
      "position": [
        784,
        448
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "redirectUrl": "={{ $('Set URL').item.json.url }}",
        "respondWith": "redirect"
      },
      "typeVersion": 2.3
    },
    {
      "id": "0bc43a61-9170-44d3-a2ca-0c0c4a9cd70b",
      "name": "Return to Initial Page3",
      "type": "n8n-nodes-base.form",
      "position": [
        1024,
        176
      ],
      "parameters": {
        "options": {},
        "operation": "completion",
        "redirectUrl": "={{ $('Set URL').item.json.url }}",
        "respondWith": "redirect"
      },
      "typeVersion": 2.3
    },
    {
      "id": "879b6246-dc05-4021-a75e-9b4076b3e728",
      "name": "Error Message about Profit Margin",
      "type": "n8n-nodes-base.form",
      "position": [
        560,
        448
      ],
      "parameters": {
        "options": {
          "formTitle": "Results",
          "buttonLabel": "Finish",
          "formDescription": "=Your input is not valid! The sum of Tax, Fee and Profit Margin must be less than 100%"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "c9b65af8-0007-4c8b-886d-332684e0064f",
      "name": "Results - Profit Margin",
      "type": "n8n-nodes-base.form",
      "position": [
        800,
        176
      ],
      "parameters": {
        "options": {
          "formTitle": "Results",
          "buttonLabel": "Finish",
          "formDescription": "=Selling Price: $ {{ $json.Price }}\nProfit: $ {{ $json.Profit }}\nProfit Margin: {{ $json.Margin }} %\nMarkup: {{ $json.Markup }} %"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "183816cf-6be4-4174-b4ac-c548150fd6df",
      "name": "Results - Markup",
      "type": "n8n-nodes-base.form",
      "position": [
        800,
        752
      ],
      "parameters": {
        "options": {
          "formTitle": "Results",
          "buttonLabel": "Finish",
          "formDescription": "=Selling Price: $ {{ $json.Price }}\nProfit: $ {{ $json.Profit }}\nProfit Margin: {{ $json.Margin }} %\nMarkup: {{ $json.Markup }} %"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "c00598bb-772a-4678-8117-5336816c084c",
      "name": "Calculate - Profit Margin",
      "type": "n8n-nodes-base.code",
      "position": [
        560,
        176
      ],
      "parameters": {
        "jsCode": "const cost = Number($('On form submission1').first().json['Products cost']);\nconst Tax = Number($('On form submission1').first().json.Tax) / 100;\nconst fee = Number($('On form submission1').first().json['Fee percentage']) / 100;\nconst margin = Number($('On form submission1').first().json['Profit Margin or Markup']) / 100;\n\n// F\u00f3rmula:\nconst price = cost / (1 - Tax - fee - margin);\n\nconst profit = price - cost - (price * Tax) - (price * fee);\n\nconst markup = 100 * (price-cost) / cost;\nconst profitMar = margin * 100\n\nreturn [{\n  json: {\n    Price: price.toFixed(2),\n    Profit: profit.toFixed(2),\n    Markup: markup.toFixed(2),\n    Margin: profitMar.toFixed(2)\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "13e69e4c-373f-43ed-8f91-3b6b7477edfe",
      "name": "Calculate - Markup",
      "type": "n8n-nodes-base.code",
      "position": [
        544,
        752
      ],
      "parameters": {
        "jsCode": "const cost = Number($('On form submission1').first().json['Products cost']);\nconst tax = Number($('On form submission1').first().json.Tax) / 100;\nconst fee = Number($('On form submission1').first().json['Fee percentage']) / 100;\nconst markup = Number($('On form submission1').first().json['Profit Margin or Markup']) / 100;\n\n// Selling price based on markup\nconst price = cost * (1 + markup);\n\n// Profit after taxes and fees\nconst profit = price - cost - (price * tax) - (price * fee);\n\n// Actual profit margin (% of selling price)\nconst margin = (profit / price) * 100;\n\nreturn [{\n  json: {\n    Price: price.toFixed(2),\n    Profit: profit.toFixed(2),\n    Markup: (markup * 100).toFixed(2),\n    Margin: margin.toFixed(2)\n  }\n}];"
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "3c7cb04c-3f29-45db-b6aa-e4e29c5d8523",
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Check Profit Margin",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check Markup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set URL": {
      "main": [
        [
          {
            "node": "Check Product Cost",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Markup": {
      "main": [
        [
          {
            "node": "Calculate - Markup",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Message about Markup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Results - Markup": {
      "main": [
        [
          {
            "node": "Return to Initial Page5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Tax and Fee": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Message about Tax and Fee",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate - Markup": {
      "main": [
        [
          {
            "node": "Results - Markup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Product Cost": {
      "main": [
        [
          {
            "node": "Check Tax and Fee",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Message about Cost",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Profit Margin": {
      "main": [
        [
          {
            "node": "Calculate - Profit Margin",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Message about Profit Margin",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission1": {
      "main": [
        [
          {
            "node": "Set URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Results - Profit Margin": {
      "main": [
        [
          {
            "node": "Return to Initial Page3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Message about Cost": {
      "main": [
        [
          {
            "node": "Return to Initial Page1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate - Profit Margin": {
      "main": [
        [
          {
            "node": "Results - Profit Margin",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Message about Markup": {
      "main": [
        [
          {
            "node": "Return to Initial Page6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Message about Tax and Fee": {
      "main": [
        [
          {
            "node": "Return to Initial Page2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Message about Profit Margin": {
      "main": [
        [
          {
            "node": "Return to Initial Page4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}