Can some one help me with a Calculated field in mongodb charts data source

I’m looking to calculate the sum of the a multiplied by sum of the b in the Charts, is that correct?

Hi @Mohammed_Noor and welcome in the MongoDB Community :muscle: !

We can’t help you without more information. Please share sample docs and explain exactly the expected output you expect.

Thanks,
Maxime.

this is a sample data

I need to sum the value of work_hours and multiplied with the sum of the value of required_number and display the value in a number chart

You can’t do this with calculated fields, but you can do so with an aggregation pipeline in the query bar. Try this:

[
   {
      "$group":{
         "_id":{ },
         "total_work_hours":{
            "$sum":"$work_hours"
         },
         "total_required_number":{
            "$sum":"$required_number"
         }
      }
   },
   {
      "$set":{
         "product":{
            "$multiply":[
               "$total_work_hours",
               "$total_required_number"
            ]
         }
      }
   }
]

Tom

2 Likes

that worked like a charm, I can’t be more grateful :grin:

1 Like