Percentage of total

RichardMGreen

Well-known Member
Joined
Feb 20, 2006
Messages
2,177
Hi all

I have a query which produces values for each entry in the table. For Example
Code:
Line1     10
Line2     12
Line3     17
Line4     7

What I would like to do is to add a third column which would give me a percantage of total. Therefore the table becomes:-
Code:
Line1     10     0.21
Line2     12     0.26
Line3     17     0.37
Line4     7      0.15

I've tried using Expr1/sum(Expr1) but it gives me 100% for each line.

Anyone any ideas?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Something like this should do it.

Code:
SELECT TLines.LineNo
, TLines.LineAmt
, [LineAmt]/(Select Sum(TLines.LineAmt) AS SumOfLineAmt from tLines) AS Percentage
FROM TLines
GROUP BY TLines.LineNo
, TLines.LineAmt;
 
Upvote 0
Thanks for that.
Unfortunately, I'm trying not to use SQL as I'll be passing the database on to people who don't know it.
They can, however, build normal queries.
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top