Skip to content
Home » Power BI Exercise » Power BI Exercise – Calculate Total Sales for Current and Previous Month

Power BI Exercise – Calculate Total Sales for Current and Previous Month

5/5 - (1 vote)

Learn how to calculate and compare sales data for the current and previous month in Power BI.

This exercise covers creating measures for both Current Month Sales and Previous Month Sales, and displaying the comparison in a chart for easy analysis.

Tasks:

  1. Create a measure to calculate Current Month Sales.
  2. Create a measure for Previous Month Sales.
  3. Display both in a comparison chart.

Solution:

Load the below dataset into Power BI-

Sales Dataset

Date SalesAmount
01-01-2024 10000
02-01-2024 50000
01-02-2024 30000
01-03-2024 25000
01-04-2024 28000
01-05-2024 32000
01-06-2024 35000
01-07-2024 37000
01-08-2024 39000
01-09-2024 41000
01-10-2024 43000
01-11-2024 45000
01-12-2024 47000



Create a measure to calculate Current Month Sales-

Now, right-click on the Sales dataset, click on 'New Measure', and write the DAX code below.

Current Month Sales =
CALCULATE(
SUM(Sales[SalesAmount]),
FILTER(Sales, MONTH(Sales[Date]) = MONTH(TODAY()))
)

Create a measure for Previous Month Sales-

Now, right-click on the Sales dataset, click on 'New Measure', and write the DAX code below.

Previous Month Sales =
CALCULATE(
SUM(Sales[SalesAmount]),
PREVIOUSMONTH(Sales[Date])
)

Display both in a comparison chart-

Add a clustered column chart to the report page. Drag the Date column to the X-axis and drag both measures to the Y-axis.

Result of Current month vs Previous month
Result of Current month vs Previous month

As you can see, the chart above is showing the results as expected.

Note: To view the current month’s sales data, ensure that the dataset contains records for the current month’s sales.

I hope you enjoyed this Power BI exercise.

Loading

1 thought on “Power BI Exercise – Calculate Total Sales for Current and Previous Month”

Leave a Reply

Discover more from Learn BI

Subscribe now to keep reading and get access to the full archive.

Continue reading