Suppose you have 2 numbers. You want to sum them up, and calculate the percentage of each number upon that sum. Say, 4 and 6. So 4 contributes 40% and 6 contributes 60% to their sum 10.

**What happens when you have negative numbers?**

I did some simple research, and the relevant articles have someone trying to calculate percentage changes from one number to another. Like financial growth reports.

My question is more of, how much each component number contributes to the sum, as a percentage. The problem comes when one of the numbers is negative. Consider the trivial case, 1 and -1. The sum is 0. You already get a division by zero error when calculating the percentage (1/0) * 100.

The solution, which is the same as that in my research, is to take the difference between the two numbers and use that as the basis. So difference of 1 and -1 is 2. So 1 contributes (1/2)*100 = 50%.

What about -1? Use the absolute function. ( abs(-1) / 2 ) * 100 = 50%.

The difference method works fine if you have only two numbers. What if you work with several? My friend actually posed this question to me. Suppose you have 6 numbers, and you want to calculate the percentage contribution for each number towards their sum.

My suggestion? *Absolute everything*. The percentage contribution of n1 is

abs(n1) / ( abs(n1) + abs(n2) + abs(n3) + abs(n4) + abs(n5) + abs(n6) ) * 100

Then my friend posed a killer question. **What if all the numbers are zero?** What’s the percentage for each number then (even though each number is zero)?

It’s for a reporting application, and my friend was wondering how to calculate the percentages. Now the sum of a bunch of zeroes is also zero. You hit the division by zero error. Even the absolute-everything method fails, since each number is zero, so there’s nothing to “absolute”.

Since there’s no defined way of calculating when all the numbers are zero, I gave the 2 obvious solutions. The first is that, since each number is zero, and the sum is zero, therefore each zero contributed 100% to the zero sum. The second is, since each number is zero, therefore each contributed 0%.

My friend chose the second solution. The most compelling reason for that choice was that it’s easier to explain the logic behind that choice to the user. It’s an edge case. When there’s no right answer, choose the answer which is easier to explain.

**UPDATE**: Steve has given 2 more alternative solutions.

**UPDATE**: I wrote an article to explain some of the confusion by some readers. How can a poorly performing product contribute the highest percentage in a company’s bottom line? Read the explanation here.

If you enjoyed this article and found it useful, please share it with your friends. You should also subscribe to get the latest articles (it’s free).

I will respectfully disagree about taking absolute values just to make percentage calculations “work”. I suggest instead, that one considers the meaning which is usually impart to the idea of a percentage: A percentage normally represents a fraction of a whole. In this context, neither the fraction nor the whole could ever be negative. My conclusion is that if you are trying to take percentages where one or more numbers might be negative, then you may want to seriously reconsider what you are doing.

Will Dwinnells last blog post..Parallel Programming: A First LookThe case in point dealt with monetary values. The values are supposed to be non-negative. Actually, they’re supposed to be all positive.

Some business logic changes later, and financial adjustments (such as credit and waivers) came into the picture. So the possibility of having zero or even negative values became real. (And has now happened)

It’s a financial report, and the users want a percentage for each value, which represents how much it contributes to the sum total. Based on this, do you have a suitable solution, Will?

Frankly, I don’t see a right or wrong answer… business-wise. Mathematically though…

[…] math, despite their math origins. How hard can it be to sum up figures, do discrete prorating, calculate percentages or find out the price based on existing […]

There are at least two other possible answers to the question “How much does each zero contribute to the sum of 0”. Since zero is equal to zero, each of the 0’s you added together contributed to the sum equally. Therefore, you could say that each 0 contributes 100 percent divided by the number of zeros (so if you add together two 0’s each contributed 50% to the sum, three 0’s would each contribute 33 1/3%, four would each contribute 25%, etc.

In computer floating-point arithmetic, since zero divided by zero is ambiguous (zero divided by a non-zero number is 0, so 0/0 should be 0; but anything divided by zero is either plus or minus infinity) the operation 0/0 results in a number called NaN, or Not a Number. [Yes, Not a Number is a number. It’s counterintuitive, but it’s true.] Because of that, a fourth possible answer is that each zero contributes NaN percent to the sum.

Hi Steve, those are good answers.

What would happen if the numbers were 0, 0, 0, 0, 4, 6? The first 4 should contribute 0%, the 5th number 40% and the last number 60%? It doesn’t make sense to me to give percentage contributions to the first 4 zeroes…

So the first answer you suggested has a specific condition. Which makes sense. And equally easy to explain to a non-tech, non-math layperson as the “all are 0%” explanation.

Your second answer is also correct. It’s a little hard to explain NaN to a layperson though… the context is a financial report. The user doesn’t care how edge cases are handled, only that they’re handled, and easily understood.

Thanks for your comment!

i have a real financial case. my business is split into category A and category B

in 1 year, category A makes profit of say 87

in the same year, category B makes a loss of -103

how do we calculate the percentange contribution of A and B ?

if i use the abs method, A contributes +45.80%, and B -54.21% ?

doesnt compute with me

thanks

Hi Surjadi, let’s say the profit/loss fluctuation of your 1st year is 190 (87 + 103). I’m using abs(-103) because we’re talking about change, not just positive change.

Then category A contributed 87/190 *100% = 45.79% to your bottom line. And category B contributed 103/190 *100% = 54.21% to your bottom line.

B made a more significant contribution to your bottom line than A (54.21 > 45.79). In this case, it just means it affected your bottom line more. That doesn’t mean you made more profit, because B was a loss.

Don’t think of the numbers with exact values (positive or negative). Think of them as how much impact the categories have on your business’s bottom line.

Dear Vincent,

thanks for your clarifications.

1 more question.

A contributes 87 ( 45.79% ), B -103 ( 54.21% ) , overall result is -16 ( 87 – 103 )

my confusion is how the percentage contribution relates to the net of -16 ?

i mean , A which contributes 87, is not 45.79% of -16 …

for both positive numbers, the percentage contributions has definite and traceable link to the total net

thanks

Surjadi, think of it this way. You started out with 0 net. Then you have -16 net. So it’s a net loss.

A contributed 45.79% to that net loss. B contributed 54.21% to that net loss.

If I were a business person, I would say B is not a good investment…

The percentages are indications of contributions to the net effect. They don’t have to be negative if the net effect is negative (-16 in this case).

Thank You very much Vincent

I learnt something new today 🙂

How i can calulate in excel the achivement % in the following case

act 34 Budget -584

act -452 Budget -676

What will be the % of achivement of actual to the budget

Hi abhilash,

34 / (34 + 584) * 100% = 5.50%

452 / (452 + 676) * 100% = 40.07%

I hope that answers the question

Dear Vincent,

Definitely a new way of viewing contribution for me.

1. Would you say this applies to for instance market growth as well?

Say:

Total market growth: -100

Segment A: 400

Segment B: -500

Then:

Contribution Segment A = 400/(400+500)*100

” = 44.4%

Contribution Segment B = 55.6%

For me, it would appear that seg A also contributes to the loss, which it does not. In terms of user-friendliness, it could be misunderstood, no?

2. When calculating in the same manner as I would if only positive numbers. Then:

Contribution Seg A = 400%

Contribution Seg B = -500%

Do you think this is wrong?

Mentioning I am not crazy with this method, since you sometimes – when difference between totalt growth and segment growth is large – get really high percentages…

Hi Folke, your first example is applicable. In order to make the terms user-friendly, I suggest using the term “market change” instead of “market loss” or “market growth”. Let the value of the number, be it positive or negative determine the state. If market change is positive, the reader will read it as a growth. If market change is negative, it’s read as a loss. This way, the terminology is clear.

If a component (eg seg A) is positive, thus providing growth, that component is still considered to be contributing to the market change. It just so happens that after everything is calculated, the final market change is negative, so it’s a loss in total. It helped in promoting growth, just not enough.

As for your second example, I’m not sure what calculation method was used. But I feel it’s

Seg A = 400 / (-100) * 100% = -400%

and

Seg B = (-500) / (-100) * 100% = 500%

But either way, I hope you see that the percentages are *really* hard to explain and understand. Which is why the absolute-everything method might be more appropriate.