sum of a column on filtered values in Gridview

I can sum a column in gridview using the below code:

$command = Yii::$app->db->createCommand("SELECT sum(net_total) FROM estimate");

$sum = $command->queryScalar();

echo 'Total ='. $sum;

I have a column in DB as discharge_date(which is date & Time field) and I want to change the sum on filter on this column.

That is if filtered data show five records, then I want the sum for only those five records.

How I can do this?