RANGE

Updated on

RANGE is a DAX function that retrieves a range of rows within a specified axis relative to the current row.

Syntax

RANGE(
   Step,
   IncludeCurrent,
   Axis,
   Blanks,
   Reset
)
Argument Properties Description
Step The desired length of the window. If negative, the window will contain the last -STEP rows before the current row. Otherwise, the window will contain the first STEP rows after the current row.
IncludeCurrent Optional A logical value specifying whether or not to include the current row. Default value is TRUE.
Axis Optional An axis reference.
Blanks Optional An enumeration that defines how BLANK values are ordered. Valid values are: DEFAULT, LAST, FIRST.
Reset Optional Specifies how the calculation restarts. Valid values are: None, LowestParent, HighestParent, or an integer.

Return Values

An interval of data rows.

Remarks

This function can be used in visual calculations only.

The includeCurrent, axis, blanks and reset parameters can be omitted.

Example 1

Given a table that summarizes the total sales for each product category and month, the following DAX query adds a column with the total sales in the last 6 months:

TotalSalesLast6Months = CALCULATE(SUM([SalesAmount]), RANGE(-5, Rows))

The screenshot below shows the visual matrix and the visual calculation expression:

DAX visual calculation

Example 2

Given the same table, the following DAX query adds a column with the total sales in the following 12 months, not including the current month:

TotalSalesFollowingYear = CALCULATE(SUM([SalesAmount]), RANGE(12, FALSE, Rows, KEEP))

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/dax/range-function-dax

2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy