Hi all I got a very stupid question which I could not figure out how to solve it.
So basically I am trying to calculate how many percentage of increment/decrement for the expense and income of current from past month.
So let's say I got these data:
Current Month Expense: 10454
Current Month Income: 2233
Last Month Expense: 15
Last Month Income: 1500
To calculate the income:
if(thisMonthtotalIncome < lastMonthtotalIncome){
incomePercentage = Math.round(thisMonthtotalIncome/lastMonthtotalIncome * 100);
}else if(thisMonthtotalIncome > lastMonthtotalIncome){
incomePercentage = Math.round((thisMonthtotalIncome/lastMonthtotalIncome));
}
To calculate the expense:
if(thisMonthtotalExpense < lastMonthtotalExpense){
expensePercentage = Math.round(thisMonthtotalExpense/lastMonthtotalExpense * 100);
}else if(thisMonthtotalExpense > lastMonthtotalExpense){
expensePercentage = Math.round((thisMonthtotalExpense/lastMonthtotalExpense));
}
I realized the percentage was somewhat wrong because from the data above, I get the expense increases by 697%. Is there any way or correct way to limit it to be in the range of 0% - 100%?
Also, I think that the formula is wrong as well cause I am so lousy at Maths.
Any suggestions? Thanks in advance!
Use these:
Always think percentage as fractions. Close to 1. Only multiply by 100 for fanciness:
Note that you never have to limit them.... never.
%DI=2233/1500=1.48666 (148.66%)
%DE=10454/15=696.9333 (69693.33%)
These are huge, and very bad because you only had \$15 at past month and now you have \$10.454. What did you do with those \$10 bucks you saved the past year?... Very bad. Numbers do not lie.
EDIT:
IF you are obtaining several NaN because you obtained a zero income|expense during the last period, this means, the metric itself is very "spiky" for your process. In this case, you can always make a smoother reference:
which calculates an Historic Income|Expense average, by taking the 80% of the actual last month value, but smoothed by the previous calculated historic value. This is enough smooth for not having a close to zero indicator. This is an "exponential average". Several averaging techniques exist for obtaining an historic moving value to use as reference.