Skip to main content
Topic: Calculate a field % of total (Read 530 times) previous topic - next topic

Calculate a field % of total

Hi Guys,

I have made a web app using PHPRad, and need to report on the % a field value compared to the sum of all the field values..

e.g.

Table:
IDProcessValue
1ArcSpray10
2Machine5
3ArcSpray12
4ArcSpray20
5Machine24
6ArcSpray34
7ArcSpray100
I want to find the percent (%) that ArcSpray is compared to the total in relation to the values.
the simple math is,
SUM (Values WHERE Process = ArcSpray) / SUM (Values) * 100 = %

I have done this in excel and access (via multiple queries)


RESULT:
ProcessPercent of Total
ArcSpray86.27
Can someone please help how I may be able to get this done?

Re: Calculate a field % of total

Reply #1
@Matt_NMS‍ your query should look like this.
Code: [Select]
SELECT ((SELECT SUM (Values) FROM table  WHERE Process = 'ArcSpray') / SUM (Values)) * 100 FROM table

Note: this was not tested. the best way to get a good query is to test it while you modify it.

 

Re: Calculate a field % of total

Reply #2
THanks, i'll have some more goes at it this week hopefully.