Hi
I have below query & i want to get average by dividing total no days by total no of entries
select sum([TotDays]),month([InvoiceDate]),year([InvoiceDate]) FROM [Sales]
where [InvoiceDate] between DATEADD(month, -12, GETDATE()) and GETDATE()
group by year([InvoiceDate]),month([InvoiceDate])
Thanks

Jignesh KumarRank #91 · 22.9K reputationPosted Nov 20, 2022, 12:12 AM EST
Hello,
Please use this query,
select isnull(sum([TotDays]),0)/count([InvoiceDate]) as Average,sum([TotDays]) as TotDays ,month([InvoiceDate]),year([InvoiceDate]) FROM [Sales] where [InvoiceDate] between DATEADD(month, -12, GETDATE()) and GETDATE() group by year([InvoiceDate]),month([InvoiceDate])