Using column value or $state in other column

I have this column:

Tables\Columns\TextColumn::make('population.sample_size')
                ->label('Sample Size')
                ->sortable(),


And I want to use that column values ​or $state to do calculations on the other columns like this:

Tables\Columns\TextColumn::make('difference')
                ->label('Difference')
                ->getStateUsing(function ($record) {
                    return $record->respondent_count - $record->population->sample_size;
                })
                ->sortable(),


But it didn't work. So how do I access 'population.size' from the $record?

Or maybe if we can use value or $state from another column it would be better. Thanks.
Screenshot_from_2023-07-14_17-39-26.png
Was this page helpful?