Creating Power BI DAX Measures for Current and Previous Quarter Sales

Mohamad MahmoodMohamad Mahmood
2 min read
Previous Quarter =
CALCULATE ( [Total Sales], PREVIOUSQUARTER ( Date[Date] ) )

To create a measure that displays the sales from the previous quarter, you can use the PREVIOUSQUARTER function in DAX. This function returns a table that contains all the dates from the previous quarter, based on the current context of the Date column.

Example Scenario

Given the following meta data:

Table NameColumn NameDescriptionData Type
DateDateCalendar dateDate
DateMonthCalendar monthText
DateYearCalendar yearInteger
SalesSaleSales valueDecimal number
SalesDateCalendar dateDate

The Date table relates to the Sales table by using the Date columns.

The model contains the following DAX measure, Total Sales = SUM(Sales[Sale])

Let’s say we need to create another measure named Previous Quarter to display the sales one quarter before the selected period.

Apply the above DAX Expression:

Previous Quarter =
CALCULATE ( [Total Sales], PREVIOUSQUARTER ( Date[Date] ) )

Explanation

• CALCULATE: This function modifies the context in which the data is evaluated.

• [Total Sales]: This is the measure you already have, which sums up the sales values.

• PREVIOUSQUARTER(Date[Date]): This function returns a table with all the dates from the previous quarter based on the current context of the Date column.

This measure will calculate the total sales for the quarter immediately preceding the selected period.

End result

Let's assume we have the following sales data:

DateSales
2024-01-15100
2024-02-15150
2024-03-15200
2024-04-15250
2024-05-15300
2024-06-15350
2024-07-15400
2024-08-15450
2024-09-15500

If the current selected period is Q3 2024 (July to September), the Previous Quarter measure would calculate the total sales for Q2 2024 (April to June).

Here's how the calculation would look:

• Q2 2024 Sales: 250 (April) + 300 (May) + 350 (June) = 900

So, the result of the Previous Quarter measure for Q3 2024 would be 900.

0
Subscribe to my newsletter

Read articles from Mohamad Mahmood directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohamad Mahmood
Mohamad Mahmood

Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He studies at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).