# Percentage share in Custom Mode

**URL:** <https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457>\
**Category:** Share What's Working\
**Created:** [February 7, 2020, 11:45am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457 "2020-02-07T11:45:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JonKemp](https://sea1.discourse-cdn.com/flex015/user_avatar/pug.phocassoftware.com/jonkemp/32/334_2.png) [@JonKemp](https://pug.phocassoftware.com/u/JonKemp)\
**Post date:** [February 7, 2020, 11:45am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/1 "2020-02-07T11:45:37Z")

</div>

Hi All,

Nifty trick to get percentage share to work in custom mode. Below are the steps to produce:

Its a little different to normal custom mode calculations, so please bear with this and please read till the end of post:  
**Scenario**  
I want a custom mode widget which shows the percentage share of the dimension I have selected. So to keep it easy, lets say I want to see % share across all branches:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/107190c68e879233c11c9f1aeb970062ba410339.png)  
The custom mode criteria is this:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/0d0fa02f4e39524ce214db63c38e1b3f354a6321.png)  
So far so good…  
**Challenge**  
Because I am in Custom mode I want to see this percentage share. I.e. What is the overall percentage of one branch over the other. So in the case of GB, the formula would need to be 350,265 / 474,032 = 73.89%.

Normal custom mode calculations cannot work out a value based on the current dimension. **This is not the case!** See below:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/07cc60bc051a1af66316b3fc842ab7a664ef9efd.png)  
So how is this done? Firstly we need to understand the building blocks to construct the value.  
How do I get the overall total to appear on each line, in this example, how do I get 474,032 on each line?  
If we refer to standard SQL the typical syntax would be _**SUM(myfield)**_, now because this is Phocas NOT SQL the language is a little different:  
`SUM({a})`  
**IMPORTANT:** the “{” is paramount for this to work so don’t skip them out 😉

This however is only the first part and on its own and it will not work..yet, to get it to work we need to expand this to be:  
`SUM({a}) OVER()`

_ **Why Over?** _  
Over is a command that is grouping based on a specific value, since its “()” we are saying group EVERYTHING.

This will give you the following:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/8f51975376a97ba640700b6853ba010a13eeb822.png)  
Now if you have understood the above (basically saying give me total value of {a}, then the final bit is easy which would be to say with the total value ascertained divide it bay the current rows (dimensions) value:  
`{a}/SUM({a}) OVER()`  
..and voila! You now have the percentage share (albeit not nicely for formatted yet!):  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/f54f15c575692b102da40663021fef3f3f8b356b.png)  
Finally lets get this looking nice, so change the formula:  
`({a}/SUM({a}) OVER()) * 100`  
This now gets it displayed correctly:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/bc7074b18c2adbe5e6f9ce2bf8925728049d0c58.png)

Success! Now if you are anything like me, you may have reading this post and jumping the gun and getting this error:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/bce43c4467827c165802aa11d7e9ab61ed4ea7bc.png)

That’s because there is a special symbol that we need to add to let the magic happen. This is “^”. So the full syntax is:  
`^({a}/SUM({a}) Over()) *100`

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/1X/445946716895d9eccc83cae3935cec28daf680a0.png)  
The “^” breaks out of standard Phocas syntax and uses SQL commands instead. There is another post I put on a while ago which talks about using case statements on the calculations [here](https://pug.phocassoftware.com/t/custom-mode-calculated-variances-returning-a-number/802/3)

Pretty nifty! I for one am happy this can be performed!

I hope this helps all you Phocas users out. Thanks to @nicolas.servouse & Nejah for their assistance in this fantastic workaround.

Regards,

Jon

---

<div class="post-metadata">

**Author:** ![dphelmken](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@dphelmken](https://pug.phocassoftware.com/u/dphelmken)\
**Post date:** [March 12, 2020, 2:01pm UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/2 "2020-03-12T14:01:38Z")

</div>

Truly great stuff here @JonKemp. I found myself getting frustrated trying to figure out a direct method of getting to this type of calculation, and your solution worked perfectly.

Thanks for sharing!

---

<div class="post-metadata">

**Author:** ![Jordon](https://avatars.discourse-cdn.com/v4/letter/j/d2c977/32.png) [@Jordon](https://pug.phocassoftware.com/u/Jordon)\
**Post date:** [May 26, 2020, 6:30am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/3 "2020-05-26T06:30:33Z")

</div>

wow! this is epic! Is there any documentation anywhere on all the commands we can use? I’ve only been able to find them by chance here in PUG so far…

---

<div class="post-metadata">

**Author:** ![JonKemp](https://sea1.discourse-cdn.com/flex015/user_avatar/pug.phocassoftware.com/jonkemp/32/334_2.png) [@JonKemp](https://pug.phocassoftware.com/u/JonKemp)\
**Post date:** [May 26, 2020, 7:06am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/4 "2020-05-26T07:06:22Z")

</div>

Hi @Jordon,

Not that I know of. I raised this when we had a meeting with Phocas and they let me know about this. I think there will need to be some trial and error with the “^” option as I am sure there are other use cases out there.

Kind Regards,  
Jon

---

<div class="post-metadata">

**Author:** ![alexlovenberg](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@alexlovenberg](https://pug.phocassoftware.com/u/alexlovenberg)\
**Post date:** [November 10, 2021, 8:25pm UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/5 "2021-11-10T20:25:09Z")

</div>

@JonKemp This was super helpful! The calculation works great to show the % of company sales for each customer. It gives me all the info I need when I am in grid mode.

However, I am trying to use this as a summary widget on my Customer scorecard, so that when I filter by a customer, I see their share of company sales as a %. When I filter with the current set up, it always says 100% (understandably since the formula is not customer specific). Does anyone have a solution?

---

<div class="post-metadata">

**Author:** ![JonKemp](https://sea1.discourse-cdn.com/flex015/user_avatar/pug.phocassoftware.com/jonkemp/32/334_2.png) [@JonKemp](https://pug.phocassoftware.com/u/JonKemp)\
**Post date:** [November 15, 2021, 8:15am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/6 "2021-11-15T08:15:09Z")

</div>

@alexlovenberg ,

Not that I know of. This “hack” allows you to inspect the entire dataset so will always be the sum of the whole and compare to row. AS soon as you want to pinpoint a row this is where you will come unstuck…unless there is another way that someone know.

Regards,

Jon

---

<div class="post-metadata">

**Author:** ![Linh](https://avatars.discourse-cdn.com/v4/letter/l/e9bcb4/32.png) [@Linh](https://pug.phocassoftware.com/u/Linh)\
**Post date:** [July 22, 2022, 1:13am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/7 "2022-07-22T01:13:06Z")

</div>

Great step by step explanation, @JonKemp !  
Thank you

---

<div class="post-metadata">

**Author:** ![dan.klob](https://sea1.discourse-cdn.com/flex015/user_avatar/pug.phocassoftware.com/dan.klob/32/1504_2.png) [@dan.klob](https://pug.phocassoftware.com/u/dan.klob)\
**Post date:** [March 3, 2023, 2:07pm UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/8 "2023-03-03T14:07:38Z")

</div>

This. is. gold. 🪙 💰 🙌🏽 Major kudos to @JonKemp for sharing this up.

---

<div class="post-metadata">

**Author:** ![oliver.fleming](https://avatars.discourse-cdn.com/v4/letter/o/7ea924/32.png) [@oliver.fleming](https://pug.phocassoftware.com/u/oliver.fleming)\
**Post date:** [July 11, 2023, 8:06am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/9 "2023-07-11T08:06:01Z")

</div>

Thought I might also share a similar solution for a slightly different but relevant use case.

Let’s say that rather than percentage share, you want to find out what “percentile” an entity falls into, eg. which products are in your top 90%, 80%, 70%… best performers

You can follow the same steps that Jon has laid out, and then use the following query in your calculated column:  
^PERCENT\_RANK() OVER (ORDER BY {a} ASC) \* 100

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/2X/3/3940420d8cb7d309ca08c3c66ab2b53904b24e9d.png)

The result should look something like this:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/phocassoftware/original/2X/3/35e3e08d6cd069ea3d6d18b6e9667325fd126120.png)

Also, if you prefer your top performers in the single digits, eg. 1st percentile, simply swap ASC with DESC to change the order:  
^PERCENT\_RANK() OVER (ORDER BY {a} DESC) \* 100

Hope this helps!

---

<div class="post-metadata">

**Author:** ![peter.clarke](https://avatars.discourse-cdn.com/v4/letter/p/258eb7/32.png) [@peter.clarke](https://pug.phocassoftware.com/u/peter.clarke)\
**Post date:** [September 9, 2025, 9:39am UTC](https://pug.phocassoftware.com/t/percentage-share-in-custom-mode/1457/10 "2025-09-09T09:39:01Z")

</div>

Jon, this was a life saver thankyou!!!
