Monday, September 10, 2018

PREVIOUS Day/Month/Year Calculations in Dax/ Power BI

PREVIOUS Day/Month/Year Calculations in Dax:

PREVIOUSDAY Function (DAX)


Returns a table that contains a column of all dates representing the day that is previous to the first date in the dates column, in the current context.

Syntax

PREVIOUSDAY(<dates>)  

Parameters

TermDefinition
datesA column containing dates.

Return Value

A table containing a single column of date values.
Example: 
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSDAY('DateTime'[DateKey]))  

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

TermDefinition
DatesA column containing dates.

Return Value

A table containing a single column of date values.
Example:
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSMONTH('DateTime'[DateKey]))  

PREVIOUSQUARTER Function (DAX):

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

Syntax

PREVIOUSQUARTER(<dates>)  

Parameters

TermDefinition
datesA column containing dates.

Return Value

A table containing a single column of date values.
Example: =CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSQUARTER('DateTime'[DateKey]))

PREVIOUSYEAR Function (DAX):



Returns a table that contains a column of all dates from the previous year, given the last date in the dates column, in the current context.

Syntax

PREVIOUSYEAR(<dates>[,<year_end_date>])  

Parameters

TermDefinition
datesA column containing dates.
year_end_date(optional) A literal string with a date that defines the year-end date. The default is December 31.

Return Value

A table containing a single column of date values.
Ex: =CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PREVIOUSYEAR('DateTime'[DateKey]))
More date and Time functions can be obtained from the link below:
https://msdn.microsoft.com/en-us/query-bi/dax/date-and-time-functions-dax
More of Time Intelligence functions:
https://msdn.microsoft.com/en-us/query-bi/dax/time-intelligence-functions-dax

No comments:

Post a Comment