# Ability to sort based off result of customfunction?

**URL:** <https://community.spicecrm.io/t/ability-to-sort-based-off-result-of-customfunction/366>\
**Category:** KReporter\
**Created:** [October 23, 2018, 8:55pm UTC](https://community.spicecrm.io/t/ability-to-sort-based-off-result-of-customfunction/366 "2018-10-23T20:55:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tessupport](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@tessupport](https://community.spicecrm.io/u/tessupport)\
**Post date:** [October 23, 2018, 8:55pm UTC](https://community.spicecrm.io/t/ability-to-sort-based-off-result-of-customfunction/366/1 "2018-10-23T20:55:17Z")

</div>

Hi,

We’re running a report for Cases Opened by Day of Week. I have a customfunction to group date\_created by converted Monday, Tuesday, Wednesday etc.

Is there a way to sort the Day of the Week (Monday/Tuesday etc) chronologically instead of alphabetically?

One solution I though might work from the gitbook was to redefine when Monday then 1, when Tuesday then 2, and sort based on that, but it doesn’t seem to be working. Can kReporter sort based off of the customfunction result in that way?

Thanks!

---

<div class="post-metadata">

**Author:** ![maretval](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@maretval](https://community.spicecrm.io/u/maretval)\
**Post date:** [October 24, 2018, 4:31pm UTC](https://community.spicecrm.io/t/ability-to-sort-based-off-result-of-customfunction/366/2 "2018-10-24T16:31:23Z")

</div>

That’s tricky one. Sorting is applied on group field label for display. Not the value itself.  
You could rename the result like this:

I dragged field Date Created twice, applied custom SQL to get the weekday.  
Then a php formula for week day names.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/3ab3252f8366b7dc2769e539080c2f4ac98575d3.png)

In present I hid Date Created Numeric (to avoid appearing below group name in fields list) and set sort flag

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/spicecrm/original/1X/03cd0cdb486223ce2fd63279155ddfa4d550354e.png)
