# Defining periods in PI AF Analyses

Discussion created by dsouzarich on Oct 13, 2015
Latest reply on Oct 14, 2015 by dsouzarich

Ever wondered how to define a period for the various Tagxxx(x) or other functions that take a start and end period. I have come up with a set of start and end periods that appear to work in a solution that I am implementing. I am keen to know if there are any better ways of setting these up. The weekly is an odd one, not sure how I worked that one out. With Weekly and on wards you need to consider your starting point, so weekly starts on a Monday at 00:00:00, etc.

Hourly – Schedule hourly

PeriodStart := 't'+Hour('*')*3600-3600

PeriodEnd := 't'+Hour('*')*3600

Daily- Schedule daily

PeriodStart := 'y'

PeriodEnd := 't'

Weekly- Schedule daily

NewPeriod := if Day('*')=2 then true else false

PeriodStart := if NewPeriod then 't'-(Weekday('*')+5)*86400 else NoOutput()

PeriodEnd := if NewPeriod then PeriodStart+7*86400 else NoOutput()

Monthly- Schedule daily

NewPeriod := If Day('*')=1 then true else false

PeriodStart := Bom('*'-(day('*')+1)*86400)

PeriodEnd :=  Bonm(PeriodStart)

Quarterly- Schedule daily

NewPeriod := if (Month('*')=1 or Month('*')=4 or Month('*')=7 or Month('*')=10) and Day('*')=1 then true else false

PeriodStart := if NewPeriod=true then 't-3mo'-(Day('*-3mo')-1)*3600*24 else NoOutput()

PeriodEnd :=  if NewPeriod then 't'-(Day('*')-1)*3600*24 else NoOutput()

Yearly- Schedule daily

NewPeriod :=  if Month('*')=1 and Day('*')=1 then true else false

PeriodStart := if NewPeriod then 't-12mo' else NoOutput()

PeriodEnd :=  if NewPeriod then 't'else NoOutput()