12-16-2016 8:00 PM
hello community -
I am following this blog : https://blogs.sap.com/2015/03/26/xs-data-services-building-cds-queries/ and i am able to get the aggregation sum, avg, etc... i am looking to implement a count but it is not working for me... again, the sum, avg functions work but count does not..
is this a bug?
my code:
var output = myTable.$query()
.$where(<MY_WHERE_CONDITION>)
.$aggregate(<MY_AGG_COLS>)
.$addFields({ COL_SUM: table.COL_SUM.$sum(),
COL_AVG: table.COL_SUM.$avg(),
COL_COUNT: table.COL_SUM.$count()
}).$execute();
then, the output....
{
COL_SUM : <CORRECT_SUM>,
COL_AVG: <CORRECT_AVG>,
COL_COUNT : { }
}
why is the COL_COUNT returning {} instead of an actual count (int) - i have tried w different columns without any luck. any help is appreciated -
thank you
12-16-2016 8:07 PM
just to add - all these functions work fine: $min(), $max(), $avg(), $sum()...
however $count() does not ... very strange - this is a SP11 system
01-13-2017 5:43 PM
not sure, what can be the reason. but it did not work for me as well. I have used a length function to get the count of a column
- Regards/Giri
01-13-2017 8:43 PM
the length function for the result of the query execution? that would give you the number of rows, not the column count... or what do you mean by ... you used the length function to get the count of a column ?