getting max value from running total by month

I have written the following query in sql server 2017 which gives me the running total of a field called numberchecked for day, month, and year and this works perfectly.  I now need the max total, by month, but am a little bit brain fogged on how to get this.  My query is below.  What do I need to add?

Table has 2 fields:
    date datetime,
    numberchecked int

select date,
		numberchecked,
		sum(numberchecked) over (partition by date order by date) as rt,
		sum(numberchecked) over (partition by datepart(month, date) order by date) as rtm,
		sum(numberchecked) over (partition by datepart(year, date) order by date) as rty
from Checked
where datepart(year, date) = 2017

Open in new window

dan hendersonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
is it just as easy as:
max(numberchecked) over (partition by datepart(month, date) ) as rtmAx,

Open in new window


Don't have 2017 to check it out.
0
Olaf DoschkeSoftware DeveloperCommented:
I assume you'd also want to get rid of all the days not at the end of the month, so just first sum grouped by month, then do the running total:

With monthly as(
select max(date) as lastdate, 
       sum(numberchecked) as tm
	    from Checked
where    datepart( year, date) = 2017
group by datepart(month, date)
)
Select lastdate,
       tm,
	sum(tm) over (partition by datepart(month, lastdate) order by lastdate) as rtm,
	sum(tm) over (partition by datepart( year, lastdate) order by lastdate) as rty
from monthly

Open in new window


Bye, Olaf.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dan hendersonAuthor Commented:
thanks.  I was having a brain cramp there.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.