## Run time calculations for linear or radial gauge

Hi,
I have a sales pipeline list with a calculated category column having these values (Cold, Warm, Hot, Won, Lost). I tried to build a linear or radial gauge to calculate the win rate (total won/total pipeline items)*100.

I tried following your example for doing run time calculations in sales distribution chart on the sales dashboard demo page: http://www.spchart.com/demo/sales-dashboard/config

However i couldn't get it to work out for me on a linear or radial gauge.

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

## Re: Run time calculations for linear or radial gauge

Hi,

I would propose:

1. Create a calculated column that would output 1 for "Won" entities, otherwise 0
2. Go to Data Source -> Aggregation
a. enter anything that's not an existing field name into Group by
b. add an aggregated value: count = count of ID
c. add an aggregated value: sumwon = sum of the calculated column from #1
3. Go to Data Source -> Advanced, add the following line of code to the aggergationSuccess function:
Code: Select all
`handlers.aggregationSuccess = function(data, logger) {   data.groups[0].winRate = data.groups[0].sumwon/data.groups[0].count * 100;   return true;}`

4. Click Process
5. Select winRate as the value for the chart.

Rostislav

Posts: 61
Joined: Fri Oct 09, 2015 10:51 am

## Re: Run time calculations for linear or radial gauge

Thanks a lot for your support, your solution worked out for me.

MohamedGaafar

Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

## Re: Run time calculations for linear or radial gauge

Hello Rostislav,

I have followed your example and everything seems to work, however my % should be ~20.5% and I am showing a tad bit above 40% for this particular view.

For this view:

Total Won (1) = 51 records
Total Items (0&1) = 248 records

Any advice would be greatly appreciated.
Attachments
chart_export.zip
Zipped due to .txt type.
wparks77

Posts: 13
Joined: Sat Dec 03, 2016 7:54 pm

## Re: Run time calculations for linear or radial gauge

Hi,
Could you also provide a template of the source list with its content (list settings -> save this list as template -> tick Include Content).

Dmitry Kozlov

Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

## Re: Run time calculations for linear or radial gauge

Yes sir and thank you very much. Please see the attached.
Attachments
Bid Log.zip
Zipped due to STP extension.
wparks77

Posts: 13
Joined: Sat Dec 03, 2016 7:54 pm

## Re: Run time calculations for linear or radial gauge

Hi! Replace your handlers.aggregationSuccess with this code and remove any extra-fields in DS -> Aggregation:
Code: Select all
`handlers.aggregationSuccess = function(data, logger) {     var count = data.items.reduce(     function(count, curr){       return count + (curr.Status == "Won");           }, 0);   data.groups[0].winRate = count/data.items.length;  return true;}`

After that choose in Dashboard -> Chart "winRate" in "Value"
YuriyMedvedev

Posts: 14
Joined: Mon Sep 26, 2016 3:05 pm

## Re: Run time calculations for linear or radial gauge

Works beautifully. I want to thank you and your team for the excellent customer support.
wparks77

Posts: 13
Joined: Sat Dec 03, 2016 7:54 pm