I am using the Table chart type in Mongo db
The first column is the month
The second column is the total number of orders for the month
The third column is the total number of orders with overdue payments for the month
I want to create a third column that is the percentage difference between the third column and the second one
So for each month, I want a third column that is the (total number of overdue payments / total number of order for the month)
Is this possible in mongo charts, seems really really simple , just comparing two columns but I haven’t figured out a solution yet
Hello kynect@Solomon_Rachamim
Yes, it is possible to create a new column in MongoDB Charts that shows the percentage difference between two columns. You can achieve this by creating a calculated field that will calculate the percentage of overdue payments out of the total number of orders for each month.
Here’s a step-by-step guide on how to create this calculated field.
Go to the Fields pane in your chart’s configuration.
Click on Add Field to create a new calculated field.
Set the Field Name to something descriptive, like “Overdue Payment Percentage”.
In the Value Expression, you’ll need to use an expression to calculate the percentage. The expression will look something like this
{
"$multiply": [
{
"$divide": [
"$totalOverduePayments",
"$totalOrders"
]
},
100
]
}
Replace “$totalOverduePayments” with the field name for the total number of orders with overdue payments, and “$totalOrders” with the field name for the total number of orders for the month.
Once you’ve added the calculated field, it should appear as a new column in your table chart, showing the percentage of overdue payments for each month.
Remember to ensure that the field names used in the expression match exactly with the field names in your data source
Best Regards,
kynect