How do I build a workflow to calculate academic GWA using n8n?

Hi everyone,

I’m trying to build an automated workflow in n8n that can compute a student’s General Weighted Average (GWA) based on their subjects, grades, and units.

I understand the basic formula, but I’m not sure how to structure it properly using n8n nodes. Ideally, I want the workflow to:

  1. Accept a list of subjects

  2. Include corresponding grades + units

  3. Multiply grade × unit for each subject

  4. Sum all totals and divide by total units

  5. Return the final GWA result

Has anyone built something similar in n8n, or could guide me on:

  • Which nodes are best for looping through subjects

  • The best way to handle the grade × unit calculation

  • How to output the final computed GWA cleanly

Any examples, JSON snippets, or suggestions would be super helpful! Thanks in advance.

1 INPUT –Use a Set node to simulate your list of subjects

{
“subjects”: [
{“subject”: “Math”, “grade”: 1.5, “units”: 3},
{“subject”: “Science”, “grade”: 1.75, “units”: 4},
{“subject”: “History”, “grade”: 2.0, “units”: 3}
]
}

2 Function Node for Calculation(code node)

// Get input data
const subjects = $json[“subjects”];

let totalGradePoints = 0;
let totalUnits = 0;

subjects.forEach(subj => {
totalGradePoints += subj.grade * subj.units;
totalUnits += subj.units;
});

const gwa = totalGradePoints / totalUnits;

// Return result
return [
{
json: {
totalGradePoints,
totalUnits,
GWA: parseFloat(gwa.toFixed(2))
}
}
];

  1. Output

{
“GWA”: 1.83,
“Total Grade Points”: 24.5,
“Total Units”: 13
}

Here’s a n8n workflow JSON for reference:

{
“nodes”: [
{
“parameters”: {
“values”: {
“boolean”: ,
“number”: ,
“string”: [
{
“name”: “subjects”,
“value”: “[{“subject”:“Math”,“grade”:1.5,“units”:3},{“subject”:“Science”,“grade”:1.75,“units”:4},{“subject”:“History”,“grade”:2.0,“units”:3}]”
}
]
},
“options”: {}
},
“name”: “Set Subjects”,
“type”: “n8n-nodes-base.set”,
“typeVersion”: 2,
“position”: [250, 300]
},
{
“parameters”: {
“functionCode”: “const subjects = JSON.parse($json[“subjects”]);\nlet totalGradePoints = 0;\nlet totalUnits = 0;\nsubjects.forEach(subj => {\n totalGradePoints += subj.grade * subj.units;\n totalUnits += subj.units;\n});\nconst gwa = totalGradePoints / totalUnits;\nreturn [{ json: { GWA: parseFloat(gwa.toFixed(2)), totalGradePoints, totalUnits } }];”
},
“name”: “Compute GWA”,
“type”: “n8n-nodes-base.function”,
“typeVersion”: 2,
“position”: [500, 300]
}
],
“connections”: {
“Set Subjects”: { “main”: [[{ “node”: “Compute GWA”, “type”: “main”, “index”: 0 }]] }
}
}

1 Like

You could just ask The n8n AI to do it for you, and then just adjust how you need the workflow to be.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.