Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Function CalcExpectedServiceLevel 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Martijn Aug-24-2016 (created) 
 | 
     
 | 
    // Calculates the weighted average service level in this iteration of those pispips that are linked to a service level 
 | 
    totaldemand := sum( this, IterationPISPIP, itpispip, 
 | 
                        guard( not isnull( itpispip.ProductInStockingPointInPeriodPlanning().GetServiceLevel() ), false ), 
 | 
                        itpispip.TotalDemand() ); 
 | 
     
 | 
    value := 0.0; 
 | 
    if( totaldemand > 0 ) 
 | 
    { 
 | 
      value := sum( this, IterationPISPIP, itpispip, 
 | 
                        guard( not isnull( itpispip.ProductInStockingPointInPeriodPlanning().GetServiceLevel() ), false ), 
 | 
                        ( itpispip.TotalDemand() / totaldemand ) * itpispip.AchievedServiceLevel() ); 
 | 
    } 
 | 
     
 | 
    this.ExpectedServiceLevel( value ); 
 | 
  *] 
 | 
} 
 |