Sdílet prostřednictvím


PREVIOUSMONTH Function (DAX)

Returns a table that contains a column of all dates from the previous month, based on the first date in the dates column, in the current context.

Syntax

PREVIOUSMONTH(<dates>)

Parameters

Term

Definition

Dates

A column containing dates.

Return Value

A table containing a single column of date values.

Remarks

Note

To understand more about how context affects the results of formulas, see Context in DAX Formulas.

This function returns all dates from the previous month, using the first date in the column used as input. For example, if the first date in the dates argument refers to June 10, 2009, this function returns all dates for the month of May, 2009.

The dates argument can be any of the following:

  • A reference to a date/time column.

  • A table expression that returns a single column of date/time values.

  • A Boolean expression that defines a single-column table of date/time values.

Note

Constraints on Boolean expressions are described in the topic, CALCULATE Function (DAX).

Example

The following sample formula creates a measure that calculates the 'previous month sales' for the Internet sales.

To see how this works, create a PivotTable and add the fields, CalendarYear and MonthNumberOfYear, to the Row Labels area of the PivotTable. Then add a measure, named Previous Month Sales, using the formula defined in the code section, to the Values area of the PivotTable.

=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSMONTH('DateTime'[DateKey]))