F
Filament2y ago
John

Using filtered result in aggregate function

I'm using ListRecords function getTableContentFooter to show the average time between two datetime fields. Like so:
{{ $this
->getTableQuery()
->selectRaw('AVG(TIMESTAMPDIFF(DAY, date_request, date_closed)) as average_time')
->whereNotNull('date_request')
->whereNotNull('date_closed')
->first()
->average_time }}
{{ $this
->getTableQuery()
->selectRaw('AVG(TIMESTAMPDIFF(DAY, date_request, date_closed)) as average_time')
->whereNotNull('date_request')
->whereNotNull('date_closed')
->first()
->average_time }}
If the user applies some filters to the overview, they are not reflected in my average. How can I apply the user applied filters to my average query? Note: I don't want to apply pagination (average should be of complete filtered result, not only current page).
2 Replies
Patrick Boivin
I haven't tested it but there's a protected method getFilteredTableQuery(), you may be able to use that instead of getTableQuery()
John
JohnOP2y ago
Ah, perfect. Thanks!
Want results from more Discord servers?
Add your server