Try this for your search (check starting/ending of the search per your requirement)
index=example earliest=-6mon@mon latest=now (assignment_group="*")
| fields contact_type ... whatever else you absolutely need...
| eval _time = relative_time(_time,"@mon")
| eval BaselineNumber=if(_time>=strptime("06/01/2017","%m/%d/%Y"),number,null())
| rename COMMENT as "If it's not a fixed date, use relative_time(now(),"@y+5mon") instead of strptime("06/01/2017","%m/%d/%Y")"
| eval AverageNumber = if(_time>=relative_time(now(),"-3mon@mon") AND _time<relative_time(now(),"@mon"),number,null())
| rename COMMENT as "The above commands are streaming and distributable, so should be above the dedup unless you have LOTS of dups."
| rename COMMENT as "By using the value of field number directly you can avoid expesive eval-case in stats"
| stats dc(BaselineNumber) as BaselineTickets
dc(AverageNumber) as AverageTickets
by contact_type _time
| stats avg(BaselineTickets) as Baseline avg(AverageTickets) as Average by contact_type
| eval Baseline = round(Baseline,0)
| eval Average = round(Average,0)
... View more