Dax Function: PREVIOUSMONTH

Category: Time Intelligence Functions 

The PREVIOUSMONTH function in Power BI is a DAX (Data Analysis Expressions) function that returns a table of date values for the previous month based on a given date column. This function is typically used in time intelligence calculations to retrieve data for the preceding month.

Purpose of the Function

The main purpose of the PREVIOUSMONTH function is to enable users to perform time-based analysis by referencing data from the previous calendar month. It is commonly used in financial and business analytics to compare metrics such as revenue, sales, or profit for the current month versus the previous month.

Type of Calculations

  • Time Intelligence Analysis: It facilitates comparisons between the current period and the previous month.
  • Dynamic Data Retrieval: The function dynamically determines the range of dates for the previous month based on the context provided by the report or data model.
  • Aggregated Measures: It works in conjunction with aggregation functions (like SUM, AVERAGE, or COUNT) to calculate metrics for the previous month.

Practical Use Cases

  1. Monthly Sales Comparison: Comparing current month’s sales with the previous month’s performance.
  2. Revenue Trends: Analyzing revenue growth or decline month-over-month.
  3. Expense Tracking: Reviewing operational costs in the previous month to identify savings or overspending.
  4. KPI Dashboards: Building dashboards that include metrics like “Last Month’s Revenue” or “Growth Since Last Month.”

PREVIOUSMONTH(<dates>)</dates>

ParameterTypeDescription
datesColumnA column containing date values (usually from a date table).

 

How Does PREVIOUSMONTH Dax Function Works?

  1. Context Evaluation: The function identifies the current date context in your report or model.
  2. Determine Previous Month: It calculates the range of dates for the previous calendar month based on the specified dates column.
  3. Return Table: A table containing the dates from the previous month is returned. You can aggregate this table with DAX functions like SUM, AVERAGE, or COUNT.

For example, if the current date context is March 2025, the function will return dates from February 1, 2025, to February 28, 2025.

What Does It Return?

The function returns a table of date values for the previous calendar month. The table can then be used in calculations or as input to other DAX functions.

When Should We Use It?

  • When you need to calculate metrics for the previous month in a report.
  • For trend analysis, such as month-over-month comparisons.
  • In KPI dashboards that include “last month” calculations.
  • When preparing financial summaries or reviewing historical performance.

Examples

Basic Usage


Sales Last Month = CALCULATE(SUM(Sales[Amount]), PREVIOUSMONTH(Dates[Date]))

This formula calculates the total sales for the previous month.

Column Usage:


Customer Count Last Month = CALCULATE(COUNT(Sales[CustomerID]), PREVIOUSMONTH(Dates[Date]))

This calculates the number of unique customers who made purchases in the previous month.

Advanced Usage


Revenue Growth MoM =
DIVIDE(
CALCULATE(SUM(Sales[Revenue]), PREVIOUSMONTH(Dates[Date])) - SUM(Sales[Revenue]),
SUM(Sales[Revenue])
)

This calculates the month-over-month revenue growth percentage.

Tips and Tricks

  • Use with Date Tables: Ensure you have a proper date table with continuous dates for accurate calculations.
  • Filter Context: Be mindful of the filter context in your visualizations, as it affects the output of PREVIOUSMONTH.
  • Combine with Aggregation Functions: The function itself does not calculate totals; pair it with aggregation functions like SUM or COUNT to get meaningful results.

Potential Pitfalls:

  • The function works on calendar months. If your organization uses a fiscal calendar, additional logic is needed.
  • Ensure your dates column has no missing or duplicated entries.

Performance Impact of PREVIOUSMONTH DAX Function:

  • Efficient Date Tables: Use optimized and indexed date tables for better performance when working with large datasets.
  • Avoid Unnecessary Filters: Applying unnecessary filters can slow down calculations, especially on large datasets.

Related Functions You Might Need

  • NEXTMONTH: Returns a table of dates for the next month.
  • SAMEPERIODLASTYEAR: Returns dates for the same period in the previous year.
  • DATESINPERIOD: Returns a range of dates for a specified period.
  • TOTALMTD: Calculates month-to-date totals for a measure.

Want to Learn More?
For more information, check out the official Microsoft documentation for PREVIOUSMONTH. You can also experiment with this function in your Power BI reports to explore its capabilities.

Unlock the full capabilities of Power BI and elevate your data insights with our specialized consulting services. Whether you need guidance on advanced DAX functions like those highlighted here, support in designing interactive dashboards, or expertise in optimizing data models for enhanced performance, our experienced Power BI consultants are equipped to deliver customized solutions for your business. Explore our Power BI Consulting Services page to discover how we can help your organization make smarter, data-driven decisions.

1. What does the PREVIOUSMONTH function do?

The function returns a table of dates for the previous calendar month, which can be used for time-based analysis.

2. Can I use PREVIOUSMONTH with fiscal months?

By default, it works with calendar months. For fiscal months, you’ll need to customize your date table.

3. What types of calculations can I perform with PREVIOUSMONTH?

You can calculate metrics like last month’s sales, revenue, customer count, or growth percentage.

4. How do I combine PREVIOUSMONTH with other DAX functions?

Use it with aggregation functions like SUM, COUNT, or AVERAGE to derive meaningful insights.

5. What is required for PREVIOUSMONTH to work?

A properly configured date column or date table is necessary for accurate calculations.