ShowAll Questionssorted byDate Posted
N c

# How to calculate AVG in monthly wise

Hi Developers, i have one scenario to calculate Yearly average  based on the months.

Ex:
Monthly                              yearly                       results
january = 100  --->            (100)/1                       100
february= 200 --->            (100+200)/2                150
March =   300 --->             (100+200+300)/3        200
April    = 400--->                (100+200+300+400)/4...
------
-----
-----
December==1200          (100+200+300+400+... +1200)/12
Luis Guilherme Marques Lino
Hello mate!

I think this might be a good solution for you!

```Integer cMonthNum = date.month();
Integer value= 0;
for ( integer i = cMonthNum; i >= 1; i--)
{
value+= (i*100);
}
return value/cMonthNum;```

Please mark as best answer if it solves your problem!

Thank you!
N c
Hi Luis,

Thanks for the quick response.

My scenario is below like.

Product value---- 30.5%(this constant)
January Product value(this is monhly) --- 20.5%------ Yearly ---- > January product value(20.5%)/Product Value(30.5%)
Februay Product value----- 30.4% ----------- Yearly------>(january poduct value(20.5%)+February Product Value(30.4%))/Product Value(30.5%)
.....
.....
.....

December Product value---- 67% ------- Yearly ---. (jan+feb+mar+apr+.....nov+december product value)/30.5%

Please help me

Thank You