Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
Is there any way to aggregate a model based on date range (i.e monthly aggregation) on dynamo db with graphql?

I am using amplify cli having dynamo database along with GraphQL API. I have a sales model which keep sales record i.e sale amount along with the date. I want to aggregate the sales amount for each month in a year to show the sales statistics on a graph which show total sales made in each month over the year. Currently I am using GraphQL queries to query/search data from the backend.

Here is the model that I am using.

type Sales @model @searchable @auth(rules: [{ allow: private }]) {
id: ID!   
userID: String! @index(name: "byAdded", sortKeyFields: ["createdAt"])   
createdAt: AWSDateTime!   
saleAmount: Float
}

Here is the example usage of graphQL query that I am currently using to get a aggregated amount for the whole year.

await API.graphql(
        graphqlOperation(searchSales, {
          filter: {
            and: [
              { userID: { eq: userId } },
              { createdAt: { range:["2022-01-01", "2022-12-31"] } },
            ],
          },
          aggregates: {
            type: 'sum',
            field: 'saleAmount',
            name: 'totalSales',
          },
        }),
      );

Currenty Query result:

{"aggregateItems": [{"name": "totalSales", "result": {"value": 4608} }], "nextToken": "WyIwZTUyNmY2JkMjUiXQ==", "total": 7}

I want to have a result like following:

aggregations : { jan: 234, feb: 343, march: 3465, ...... } 
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda