© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
4 replies
David | Fortune Validator

Summarizer On Custom Table

Hi all

I am struggling with a custom table on filament v4. I need a SUM at the bottom fo the table much like we do on non customer tables. However I am getting the following error
App\Filament\Clusters\Reports\Pages\InternetClients::getTableSummarySelectedState(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, null given, called in /Users/davidwhicker/Development/Herd/misce-filament/storage/framework/views/bcf55eaeae8fe2b8d0b210a2bb5b1d19.php on line 161
App\Filament\Clusters\Reports\Pages\InternetClients::getTableSummarySelectedState(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, null given, called in /Users/davidwhicker/Development/Herd/misce-filament/storage/framework/views/bcf55eaeae8fe2b8d0b210a2bb5b1d19.php on line 161


Here is my code:
        return $table
            ->records(function (array $filters): Collection {
                $invoices = Invoice::query()
                    ->selectRaw('sum(sub_total) as sub_total, sum(profit) as profit, YEAR(date) as year, COUNT(id) as count, AVG(sub_total) as average , client_id')
                    ->with('client')
                    ->whereRelation('client', 'origin', 'internet')
                    ->groupByRaw('year, client_id')
                    ->orderBy('year', 'desc')
                    ->get()
                    ->toArray();

                return  collect($invoices)
                    ->when(
                        filled($year = $filters['year']['value'] ?? null),
                        fn (Collection $data): Collection => $data->where(
                            'year', $year
                        ),
                    );
            }
            )
            ->columns([
                TextColumn::make('profit')->numeric(decimalPlaces: 0)->summarize([Sum::make('profit')]),
            ])
            ->filters([
                SelectFilter::make('year')->options(Years::currentAndPreviousYears(5))->default(date('Y')),
            ], layout: FiltersLayout::AboveContent);
        return $table
            ->records(function (array $filters): Collection {
                $invoices = Invoice::query()
                    ->selectRaw('sum(sub_total) as sub_total, sum(profit) as profit, YEAR(date) as year, COUNT(id) as count, AVG(sub_total) as average , client_id')
                    ->with('client')
                    ->whereRelation('client', 'origin', 'internet')
                    ->groupByRaw('year, client_id')
                    ->orderBy('year', 'desc')
                    ->get()
                    ->toArray();

                return  collect($invoices)
                    ->when(
                        filled($year = $filters['year']['value'] ?? null),
                        fn (Collection $data): Collection => $data->where(
                            'year', $year
                        ),
                    );
            }
            )
            ->columns([
                TextColumn::make('profit')->numeric(decimalPlaces: 0)->summarize([Sum::make('profit')]),
            ])
            ->filters([
                SelectFilter::make('year')->options(Years::currentAndPreviousYears(5))->default(date('Y')),
            ], layout: FiltersLayout::AboveContent);


I would really appreciate any help if anyone has a moment as I need totals on quite a few custom tables. It could be a simple SQL / PHP issue my end as opposed to a Filament restriction.
Solution
Maybe its a bit late but i posted a quick fix in here:
https://github.com/filamentphp/filament/issues/17286
GitHub
[4.x] Table summarize with custom data · Issue #17286 · filamentp...
Package filament/filament Package Version v4.0.0 Laravel Version v12.23.1 Livewire Version v3.0.0 PHP Version PHP 8.4.11 Problem description When declaring a table either through the Widget menu or...
[4.x] Table summarize with custom data · Issue #17286 · filamentp...
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

custom summarizer
FilamentFFilament / ❓┊help
3y ago
Table Summarizer Bug on PostgreSQL
FilamentFFilament / ❓┊help
3y ago
SUMMARIZER USING CUSTOM DATA
FilamentFFilament / ❓┊help
4mo ago
Duplicate summarizer
FilamentFFilament / ❓┊help
15mo ago