I hope that I understood your goal. Have a look at the following code and feel free to change it according to your needs:
create table #Averages (id int, Year_Mnth int, Counts int)
insert into #Averages values (372, 202302, 13)
,(372, 202303, 7)
,(372, 202304, 3)
,(372, 202305, 16)
,(372, 202306, 9)
,(372, 202307, 17);
WITH CTE as(
Select *, SUM(Cast(Counts as decimal(10,2))) OVER (ORDER BY Year_Mnth) as MovingSum
, Count(Cast(Counts as decimal(10,2))) OVER (ORDER BY Year_Mnth) as MovingCount
, AVG(Cast(Counts as decimal(10,2))) OVER (ORDER BY Year_Mnth) as MovingAvg
, ROW_NUMBER() OVER (ORDER BY Year_Mnth) as RowNumber
from #Averages
)
Select *
from CTE
--where Year_Mnth between 202302 and 202306
where RowNumber = 5
order by Year_Mnth;