Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Percentage Calculation

Posted on 2010-11-08
5
Medium Priority
?
397 Views
Last Modified: 2012-06-27
Pl. See Code Snippet1278892
Sql Server 2005

The result of a tsql is 

tmtr    aMtr    bMtrpercentage  years   months
----------------------------------------------
4431	4380	51	0.988490	2010	7
8946	8946	0	1.000000	2010	8
1179	1083	96	0.918575	2010	10
----    -----   ----
14556   14409   147
-----   -----   -----

1. Total of Tmtr is 14556
2. Total of Amtr is 14409
So the Percentage of Amtr is calculated as 14409/14556 = 98.99%

But why this do not reconcile with (0.9884+1.00+0.9185)/3 = 96.89%

The percentage difference is 2.10 

Why is there difference?

Open in new window

0
Comment
Question by:Mehram
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:raulggonzalez
ID: 34083618
Because mathematically they are different....

You have to do the percentage of your totals, not the average of the partial amounts.


Cheers
0
 
LVL 8

Accepted Solution

by:
raulggonzalez earned 1000 total points
ID: 34083687
One graphic example


100 - 99  --> 0.99
 
200 - 199  --> 0.995
 
300 - 299  --> 0.99666666666666666666666666666667
 
            SUM / 3 --> 0,99388888888888888888888888888889

but the percentage of the sum is

600 - 150 --> 0,995



So, unfortunately they are different, maybe without decimals you can get the same result like

100 - 25 --> 0.25
200 - 50 --> 0.25
300 - 75 --> 0.25
                   sum / 3 = 0.25

600 - 150 -> 0.25


but playing with decimals... better calculate the percentage of the sum.


Cheers
0
 
LVL 8

Assisted Solution

by:lomo74
lomo74 earned 1000 total points
ID: 34083712
because (a+b+c) / (d+e+f) != ((a/d)+(b/e)+(c/f))/3
you simply cannot compute an "average percentage" by calculating the average of partial percentages.
suppose you have two samples:
1 out of 2   (50%)
100 out of 100 (100%)
would you say total percentage is 75%, just because 75 is average value between 50 and 100?
no, the correct formula would be  (1+100) / (2+100) = ~99%
hope this is clear now
cheers - Lorenzo -
0
 

Author Comment

by:Mehram
ID: 34083787
Hi experts

Now I got it.

Thanks
0
 

Author Closing Comment

by:Mehram
ID: 34085177
(A+B)/(C+D)=A/C+B/D
THE EQUATION CANNOT B TRUE IS EASY TO UNDERSTAND AND REMEMBER.
THANX FOR YOUR HELP
REGARDS:
(MAT)
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question