I want to create a Dashboard data source and widget that displays one bar per year (e.g. 2023, 2024, 2025), where each bar represents the sum of net_price grouped by order_date (year).
However, the documentation does not include an example of how to correctly configure a date-based dimension for grouping (year/month) or how to make the widget use order_date as a date field.
How should I define the Data Source (dimension + metric) and configure the widget to achieve yearly grouping of orders by order_date?
$reportQueryBuilder->onConfigureQuery(
function (QueryBuilder $query, ReportDimension $dimension, array $metrics) {
$query->addSelect([
Db::raw('MAX(order_date) as oc_dimension_label'),
]);
}
);
The error:
"SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'wanger_system.renatio_orders_orders.order_date' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (Connection: mysql, SQL: select DATE(order_date) AS oc_dimension, order_date AS oc_dimension_label, sum(renatio_orders_orders.net_price) as oc_metric_total_amount from renatio_orders_orders where DATE(order_date) is not null and deleted_at is null and order_date between 2020-01-01 00:00:00 and 2025-11-27 23:59:59 group by oc_dimension order by oc_dimension asc)" on line 824 of /Users/michalplodowski/Herd/wanger-system/vendor/laravel/framework/src/Illuminate/Database/Connection.php
This was a confirmed bug. The fix will be available in the next patch release (v4.0.20).
For date dimensions you typically don’t need a labelColumnName at all - the date is the label and the UI formats it appropriately. So your code could be simplified to: