Power BI can be quite useful when we are working on dates. It has some powerful built-in formulas that allow you to do calculations based on dates.
One common scenario where you have to perform calculations with dates would be to find out how to calculate monthly sales.
In this tutorial, we will learn how to calculate current month and previous month sales in Power BI with different examples.
How to Calculate Current Month Sales in Power BI
This example shows how to calculate current month sales in Power BI.
Let’s consider a simple scenario:
You manage a small bakery and want to analyze your monthly sales performance in Power BI to track how your bakery is doing over time.
Specifically, you want to compare the current month’s sales with the previous month to understand trends and decide about the market.
According to this scenario, we have an Excel file named SweetDelights_Sales_2024 that contains the Date and Sales Amount column. Check the screenshot below.
Now follow the below steps to calculate the current month’s sales:
1. Open Power BI Desktop and load data using the Get data option. Then, you can see data in the Data pane.
2. Under the Home tab, click New measure.
3. In the formula bar, Put the below expression. Then click Commit.
Current Month Sales =
CALCULATE(
SUM('SalesData2024'[Sales Amount]),
FILTER(
'SalesData2024',
MONTH('SalesData2024'[Date]) = MONTH(TODAY())
)
)
Where:
- Current Month Sales = This is the name we give to our measure. It represents the Current Month’s sales.
- CALCULATE() = It’s like telling Power BI to calculate based on certain conditions or filters.
- SUM(‘SalesData2024′[Sales Amount]) = This calculates the total sum of sales amounts from the SalesData2024 table.
- FILTER = It’s like applying a condition to select specific rows or data from a table.
- MONTH(‘SalesData2024′[Date]) = This extracts the month component from the date column in the SalesData2024 table.
- MONTH(TODAY()) = This gets the current month from today’s date.
4. After that, Under the Home tab, expand Visual gallery(black box) -> Click the Table visual.
5. Then, using the +Add data option, add Date, Sales Amount, and Current Month Sales into the Column field.
6. After that, you’ll notice that only the February month data is displayed in the “Current Month Sales” because I’m implementing it in February.
This way, you can calculate current month sales in Power BI.
Calculate Previous Month Sales in Power BI
This example shows how to calculate the previous month’s sales in Power BI.
1. Under the Home tab, click New measure.
2. In the formula bar, Put the below expression. Then click Commit.
Previous Month Sales =
CALCULATE(
SUM('SalesData2024'[Sales Amount]),
FILTER(
'SalesData2024',
MONTH('SalesData2024'[Date]) = MONTH(TODAY())-1
)
)
Where:
- Current Month Sales = This is the name we give to our measure. It represents the Previous Month’s sales.
- CALCULATE() = It’s like telling Power BI to calculate based on certain conditions or filters.
- SUM(‘SalesData2024′[Sales Amount]) = This calculates the total sum of sales amounts from the SalesData2024 table.
- FILTER = It’s like applying a condition to select specific rows or data from a table.
- MONTH(‘SalesData2024′[Date]) = This extracts the month component from the date column in the SalesData2024 table.
- MONTH(TODAY())-1 = This gets the previous month from today’s date.
3. After that, Under the Home tab, expand Visual gallery(black box) -> Click the Table visual.
4. Then, using the +Add data option, add Date, Sales Amount, and Previous Month Sales into the Column field.
5. After that, you’ll notice that only the January sales data is displayed in the “Previous Month Sales” because I’m implementing it in February.
This way, you calculate the previous month’s sales in Power BI.
After that, you can add these value visualizations to your report canvas. Then, you will see the current and previous month’s sales displayed visually, allowing you to track your bakery’s performance and make beter decisions.
This tutorial taught us how to calculate the current month’s sales in Power BI and how to calculate the previous month’s sales in Power BI.
Also, you may like some more Power BI articles:
- How to Add Data to Existing Table in Power BI
- Create a Measure Table in Power BI
- Create Table Visual in Power BI
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com
This doesn’t work if you have multiple years in the dataset. For example, I need to compare this month to last month. Using the measures provided, it will count all sales for March reglardless of year. Therefore, it’s calculating all sales in March over the years, not just March 2024. Is there a way to only calculate current months sales? I’ve seen measures that also look at current year, but this wont work for previous sales if the current month is January. Any ideas?