Calculate Total Revenue for Each Month in SQL Server

Welcome to Excel Jet Consult blog post. In this SQL Server video tutorial, we are going to learn how to calculate total revenue for each month. Let’s get started.

Dataset

The screenshot contains a simple select all statement to fetch all the records in the Monthly Sales table

Total Revenue for Each Month

To calculate the Total Revenue for Each Month, we going to write the following SQL query:

SELECT
YEAR(TransactionDate) AS Year,
MONTH(TransactionDate) AS Month,
SUM(Revenue) AS TotalRevenue
FROM
[‘Monthly Sales$’]
GROUP BY
YEAR(TransactionDate),
MONTH(TransactionDate)
ORDER BY
Year,
Month;

Select the query and click on Execute

In the above above query, we extracted the year and month values from the TransactionDate column and then group the data based on the year and month values. We calculated the sum of revenue for each group and finally, arranged the results in ascending order by year and month.

Posted in Blog.

Leave a Reply

Your email address will not be published. Required fields are marked *