SELECT period_fact as period
,month_fact as month
,year_fact as year
,region_fact as region
,sum_fact
,count_fact
,sum_plan
,sum_plan / COUNT(period_fact) OVER(PARTITION BY region_fact, month_fact, year_fact) as plan_uniform
FROM child
CASE
WHEN period_fact = MAX(period_fact) OVER(PARTITION BY region_fact, month_fact, year_fact)
THEN sum_plan
ELSE 0
END
sum_plan / COUNT(*) OVER(PARTITION BY region_fact, period_fact)