Is there a way to do rate calculation in Chart

I am trying to create a month-over-month rate trend chart. What it would do is to bin by the date field of my data, which is like a $group operation, and then do a Sum(amountA) / Sum(amountB) `.

I am wondering if this is do-able with Mongo Chart?
Thank you!

Hello @williamwjs ,

Certainly! You can create a month-over-month rate trend chart using MongoDB Charts. Let’s break down the steps to achieve this.

Ensure that your data includes a date field and the relevant amountA and amountB fields.
The date field will be used for binning…

In MongoDB Charts, create a new chart.
Choose the appropriate data source (your collection).
Set the aggregation pipeline to group by the date field (similar to a $group operation).
Within the $group stage, calculate the sum of amountA and amountB.

Add a calculated field to your aggregation pipeline that computes the rate: rate = Sum(amountA) / Sum(amountB).

Use a line chart or other suitable chart type.
Set the x-axis to the date field.
Set the y-axis to the calculated rate.

Adjust labels, titles, and other visual elements as needed.
Preview the chart to ensure it displays the desired month-over-month rate trend.
Refine the chart settings if necessary.
Remember that MongoDB Charts provides a free tier with data transfer limits, so be mindful of your usage. If your data volume exceeds the free tier, additional charges may apply.

Best Regards,