Group by date and summarize number of pages

I have a table that records each book read, the user, number of pages read and the date. I have used summarize for displaying the total number of pages read and also used ->defaultGroup to group by month and year. This looks great, but the summarize result is not correct.

return $table
            ->columns([
                Tables\Columns\TextColumn::make('user.name')
                    ->label('Reader')
                    ->searchable(),
                Tables\Columns\TextColumn::make('book.title')
                    ->label('Book')
                    ->searchable(),
                Tables\Columns\TextColumn::make('book.author.name')
                    ->label('Author')
                    ->searchable(),
                Tables\Columns\TextColumn::make('date')
                    ->date('M Y')
                    ->searchable(),
                Tables\Columns\TextColumn::make('pages')
                ->summarize(Sum::make('pages')),
            ])
            ->defaultGroup(
                Group::make('date')
                    ->getTitleFromRecordUsing(fn(Reading $record): string => $record->date->format('M Y'))
                    ->orderQueryUsing(fn(Builder $query, string $direction) => $query->orderBy('date', 'desc'))
                    ->collapsible(),
            )


As you can see on Date: Dec 2020 the sum of pages shows 243, which is not correct.
Screenshot_2024-01-05_at_02.43.31.png
Was this page helpful?