Skip to main content
August 23, 2021
Question

How to make a sum from an aggregate queryEntity ?

  • August 23, 2021
  • 2 replies
  • 0 views

Hi,

I'm trying to make a simple SUM query but it does not return what I need.

The query returns a datasubset with 2 lines (quantities: 45 and 46), but I was expecting the query to return 91.
(I would like to avoid using the sum() function in this example).

Could you tell me what is missing please ?

  a!queryEntity(
    entity: cons!CJT_VEHICLES,
    fetchTotalCount: true,
    query: a!query(
      aggregation: a!queryAggregation(
        aggregationColumns: {
          a!queryAggregationColumn(
            field: "quantity",
            alias: "quantity",
            aggregationFunction: "SUM",
            isGrouping: true
          )
        }
      ),
      logicalExpression: a!queryLogicalExpression(
        operator: "AND",
        filters: {
          a!queryFilter(
            field: "type",
            operator: "=",
            value: ri!typeId
          )
        },
        ignoreFiltersWithEmptyValues: true,
      ),
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: -1
      )
    )
  )

2 replies

mikes0011
Brainy
August 23, 2021

I think your first issue is that you have "isGrouping" set to TRUE in your aggregation column.

The Expression Guru
August 24, 2021

Ok I see, now it works (I've forgot to add a second "queryAggregationColumn" with grouping=true)

Thank you Mike.