Solved

Percentage Calculation

Posted on 2010-11-08
5
385 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
  • 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 250 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 250 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

733 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