# BUG : unable to sort by calculated percentage field

**URL:** <https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398>\
**Category:** KReporter\
**Created:** [December 6, 2018, 4:04pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398 "2018-12-06T16:04:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hvfibrecrm](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@hvfibrecrm](https://community.spicecrm.io/u/hvfibrecrm)\
**Post date:** [December 6, 2018, 4:04pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/1 "2018-12-06T16:04:51Z")

</div>

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

---

<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:** [December 6, 2018, 5:30pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/2 "2018-12-06T17:30:47Z")

</div>

How is calculation made? Did you write a formula in formula field?  
What is the type of the field under present tab?

---

<div class="post-metadata">

**Author:** ![FibreCRM\_Simon](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@FibreCRM\_Simon](https://community.spicecrm.io/u/FibreCRM_Simon)\
**Post date:** [December 10, 2018, 4:41pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/3 "2018-12-10T16:41:35Z")

</div>

Its a calculated field (fixed field with formula) from two fields (1 x currency and 1 x decimal) which we display as a percentage (override type). example. Formula = ({total} / {target}) \* 100  
The display is correct but when we sort the column data is treated alphanumerically.

---

<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:** [December 11, 2018, 5:42pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/4 "2018-12-11T17:42:48Z")

</div>

The sort is applied on database field. Not on calculated field.  
Can you move your formula to customFunction or are total and target already issued by complexe calculation?  
Drag your table field for total and write something like  
IF({t}.target \> 0, {t}.{f} / {t}.target \* 100, 0)

---

<div class="post-metadata">

**Author:** ![stephen.roy](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@stephen.roy](https://community.spicecrm.io/u/stephen.roy)\
**Post date:** [December 12, 2018, 9:20am UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/5 "2018-12-12T09:20:59Z")

</div>

Hi Val, the calculation is made up of 2 different module values being summed .  
im not sure it’s possible to perform the same action with a custom function is it?

[https://FIBRECRM.tinytake.com/media/90448c?filename=1544606429250\_12-12-2018-09-20-27.png&sub\_type=thumbnail\_preview&type=attachment&width=1199&height=322](https://FIBRECRM.tinytake.com/media/90448c?filename=1544606429250_12-12-2018-09-20-27.png&sub_type=thumbnail_preview&type=attachment&width=1199&height=322)

---

<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:** [December 12, 2018, 9:39am UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/6 "2018-12-12T09:39:14Z")

</div>

Stephen,  
let’s try out.  
Drag field Total won a second time  
Then IF({t}.annual\_target \> 0, {t}.{f} / {t}.annual\_target \* 100, 0)  
You will have to check the technical path for field “annual\_target”  
If fields involved are in a cstm table, please use {tc} instead of {t}

---

<div class="post-metadata">

**Author:** ![stephen.roy](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@stephen.roy](https://community.spicecrm.io/u/stephen.roy)\
**Post date:** [January 3, 2019, 2:23pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/7 "2019-01-03T14:23:54Z")

</div>

Hi Val, that wont work as the target is in Users\_cstm but the total won is in Accounts\_cstm.

---

<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:** [January 4, 2019, 4:22pm UTC](https://community.spicecrm.io/t/bug-unable-to-sort-by-calculated-percentage-field/398/8 "2019-01-04T16:22:51Z")

</div>

ok. I understand now.  
I think a kreporterfield would do, I’ll test that first.
