Changing aggregation type in Views does not apply until field is deleted and re-added

Created on 12 July 2025, 3 months ago

Problem/Motivation

In Views, changing the aggregation type of a field (e.g., from Count to Sum or Average) does not take effect after saving. The View continues to apply the old aggregation type, even after clearing caches. The UI appears to save the change, but the output doesn't reflect it.

Steps to reproduce

1. Create a View and enable `Use aggregation` under the "Advanced" section.
2. Add a numeric field (e.g., node ID or a custom integer field).
3. Set its aggregation type to "Count" and save the View.
4. Now go back and try to change the aggregation type to "Sum", "Average", or any other.
5. Save the View and clear all caches.
6. Reload the View output.

Proposed resolution

The only way to make the new aggregation type work is to:
- Delete the field from the View entirely.
- Set `Use aggregation` to **No** and save the View.
- Re-enable `Use aggregation`, then re-add the field and set the desired aggregation type.
This resets the internal state and makes the new aggregation type apply correctly.

- Drupal 9.5.x
- Drupal 10.5.x

Remaining tasks

When an aggregation type is changed and the View is saved, the new aggregation should immediately reflect in the output, without needing to delete and reconfigure the field.

API changes

This appears to be a bug in the Views UI. The field’s aggregation type doesn’t update properly unless the field is deleted and re-added, which is not ideal for user experience.

🐛 Bug report
Status

Active

Version

10.5

Component

views.module

Created by

🇮🇳India Neelanjana Das

Live updates comments and jobs are added and updated live.
  • views

    Involves, uses, or integrates with views. In Drupal 8 core, use the “VDC” tag instead.

Sign in to follow issues

Comments & Activities

  • Issue created by @Neelanjana Das
  • 🇳🇿New Zealand quietone

    Drupal 10 is in maintenance mode and this doesn't meet the criteria for inclusion. Does this occur on Drupal 11.x, or 11.2?

    There are quite a few issues for view, have you checked for a duplicate?

    In Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies .

  • 🇮🇳India Neelanjana Das

    Hello quietone,

    I’ve tested this bug on a clean install of Drupal 11, and I confirm that the issue still occurs.

    Steps followed:
    - Enabled Views aggregation
    - Added contextual filters
    - Result: Aggregation did not work as expected - no change in output.

    This appears to be related to the existing issue: 🐛 Aggregation not working css and js cache directories not being created Active ( https://www.drupal.org/project/drupal/issues/3381293 🐛 Aggregation not working css and js cache directories not being created Active ), which has been open since D9 and is still unresolved.

    However, since the bug is active in Drupal 11, I’m reporting it with fresh confirmation and testing. Please let me know if this issue should be merged or kept separate. I’m happy to help test patches or track this further.

    Thanks!

  • 🇳🇱Netherlands Lendude Amsterdam

    At step "4. Now go back and try to change the aggregation type to "Sum", "Average", or any other." the dialog doesn't close and if I look in the watchdog I see:

    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 728 of /var/www/html/web/core/modules/views/src/Plugin/views/field/EntityField.php).

    So definitely something broken here it seems like.

    Removed the issue that was marked as related since it has nothing to do with this (totally different kind of aggregation)

Production build 0.71.5 2024