cancel
Showing results for 
Search instead for 
Did you mean: 

How to Average of Forecast in APO Macro

Former Member
0 Kudos

Hello

I want to calculate Average of Forecast for a particular planning horizon (12Months) but only for months with value greater than 0

Example

Jan       Feb      Mar      Apr      May     Jun       Jul        Aug      Sept     Oct      Nov     Dec

10         20        30        0          40        15        0          50        0          20        10        47

The Average should be 237/ 9 and NOT 237 / 12.

How can I achieve this in APO Macro?

Initialize a counter that counts only when the value is greater than 0 etc ….

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

Here is some raw code that can help you in determining the number of periods with non zero

values.

Macro Name

Set loop variable

LAYOUTVARIABLE_SET('LP' ; 1)

Do loop

Step for loop ( define number of Iterations )

if Keyfigure value > 0

Action box  increment the counter

LAYOUTVARIABLE_SET('LP';(LAYOUTVAR_VALUE('LP')+1))

end if

enddo

This above pseudo code will help you to calulate the number of periods with non zero value.

then you can use normal Sum to get the sum of the key figure values for the whole horizon.

Average can be calculated by dividing the sum by number of periods with non zero values.

Hope this helps you.

Regards,

Anurag

Former Member
0 Kudos

Hello Anurag,

Can you please explain a bit bette? I tried that but no success.

Former Member
0 Kudos

Hi,

yes, there is no other way. Define a STEP (1 iteration) to initialize counter (sum and number of periods actually used) and a second STEP that adds the iteration history to the sum variable and increments the number of periods IF history>0. Third STEP that divides sum by number of periods... Standard functions and forecast models will consider zeroes as valid history values and include them in the calculations.

thanks,

J.