I want to count the number of consultingdays each month from the current year. And I want add this values into a line chart. But it doesn't work.

If I run the visualforce page I get the error field 'Consultingmonth__c' can not be grouped in a query call

Could you can tell me if my way correct? Is the transport from the query to the chart correct?

Public Class BT_ChartData {
    Public String BT_Month { get; set; }
    Public Integer BT_CountDays { get; set; }
    public BT_ChartData(String BT_Month, Integer BT_CountDays) {
        this.BT_Month = BT_Month;
        this.BT_CountDays = BT_CountDays;

Public List<BT_ChartData> getBT_Data() {
    List<BT_ChartData> data = new List<BT_ChartData>();
List<AggregateResult> AR_BT_List = [SELECT Count(Name) Counter FROM CustomObject__c WHERE Consultingday__c = THIS_YEAR GROUP BY Consultingmonth__c];
    FOR (AggregateResult AR_BT : AR_BT_List) {    
    data.add(new BT_ChartData(String.valueOf(AR_BT.get('Consultingmonth__c')), Integer.valueOf(AR_BT.get('Counter'))));
    return data;

<apex:chart height="390" width="950" data="{!BT_Data}">

    <apex:lineSeries axis="left" fill="false" xField="BT_Month" yField="BT_CountDays" markerType="circle" markerSize="4" markerFill="#FF0000">
        <apex:chartlabel />
    <apex:axis type="Numeric" position="left" fields="BT_Countdays" minimum="0" title="" grid="true"/>
    <apex:axis type="Category" position="bottom" fields="BT_Month" title=""/>    
    <apex:legend position="bottom"/>         

  • What is the data type of Consulting Month? Also, you didn't put it in your query, so it would not appear as a value in the results anyways.
    – sfdcfox
    Jun 5, 2019 at 16:30
  • It's a formula field fype number. The field just show the month number. I add this field because it is not possible to use the function Calender_Month(Consultingday__c) in aggregateresult.
    – peXeq
    Jun 6, 2019 at 6:03
  • I have no more ideas, can someone help me
    – peXeq
    Jun 13, 2019 at 14:09
  • What data type is ConsultingDay__c? You should be able to use date functions on the field. If not, you'll need to write a wrapper class and use that method instead.
    – sfdcfox
    Jun 13, 2019 at 14:34
  • ConsultingDay__c is a datefield, but if I try to add this field to my query --> List<AggregateResult> AR_BT_List = [SELECT Consultingday__c, Count(Name) Anzahl FROM CustomObject__c WHERE Consultingday__c = THIS_YEAR GROUP BY CalenderMonth(Consultingday__c)]; I get the error "Only date aggregate functions are allowed as grouping expressions: CalenderMonth" How can I group by calendermonth?
    – peXeq
    Jun 19, 2019 at 18:47


You must log in to answer this question.

Browse other questions tagged .