DAX Functions - Time Intelligence Functions
DAX Functions - Time Intelligence Functions
Time Intelligence
What is Time Intelligence?
Time Intelligence means doing calculations over periods of time or dates. All the Time
Intelligence Functions will need a date column to perform the calculations, and this date
column should contain unique, no null and contiguous date values to get the accurate
results.
Time Intelligence simply means doing BI calculations over periods of time, or over
dates. For example, a common request in many reports is to show a value, such as Sales,
aggregated month-by-month, from the beginning of each year, so that you know, in this case,
what were the total sales, in that year, up to the given month. DAX, Data Analysis
Expressions, the language of Power BI, includes many predefined time intelligence functions,
including TOTALYTD, which is exactly the function you need to use in this particular
scenario.
Many data analysts prefer to create their own date tables, which is fine. In Power BI
Desktop, you can specify the table you want your model to use as its date table, and
subsequently create date-related visuals, tables, measures, and so on, using that table's date
data. When you specify your own date table, you control the date hierarchies created in your
model, and use them in measures and other operations that use your model's date table.
To make DAX Time Intelligence functions work properly set date dimension table as
“Mark as date table”.
Setting your own date table
To set a date table select the table you want to use as a date table in the Fields pane,
then right-click the table and select Mark as date table Mark as date table in the menu
that appears, as shown in the following image.
www.abtrainings.com
Power BI Analytics Benchmark (AB) Trainings
You can also select the table and then select Mark as Date Table from the Modeling
ribbon, shown here.
When you specify your own date table, Power BI Desktop performs the following
validations of that column and its data, to ensure that the data
contains unique values
contains no null values
contains contiguous date values (from beginning to end)
if it is a Date/Time data type, it has the same timestamp across each value
Once you specify a date table, you can select which column in that table is the date
column. You can specify which column to use by selecting the table in the Fields pane, then
right-click the table and select Mark as date table Date table settings. The following
window appears, where you can select the column to use as the date table from the drop-
down box.
www.abtrainings.com
Power BI Analytics Benchmark (AB) Trainings
All the Time Intelligence Functions will need a date column to perform the
calculations, and this date column should contain unique, no null and contiguous date values
to get the accurate results.
TOTALMTD
Evaluates the value of the expression for the month to date, in the current context.
TOTALMTD will give Running Totals or cumulative sum for each Month.
Example
TOTALQTD
Evaluates the value of the expression for the dates in the quarter to date, in the
current context. TOTALQTD will give Running Totals or cumulative sum for each Quarter.
Example
Total QTD = TOTALQTD(SUM(Orders[Sales]), Dim_Date[Date])
TOTALYTD
www.abtrainings.com
Power BI Analytics Benchmark (AB) Trainings
Evaluates the year-to-date value of the expression in the current context. TOTALYTD
will give Running Totals or cumulative sum for each year.
Example
PREVIOUSDAY
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.
Example
Previous Day = CALCULATE(SUM(Orders[Sales]), PREVIOUSDAY(Dim_Date[Date]))
PREVIOUSMONTH
www.abtrainings.com
Power BI Analytics Benchmark (AB) Trainings
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.
Example
Previous Month = CALCULATE(SUM(Orders[Sales]), PREVIOUSMONTH(Dim_Date[Date]))
PREVIOUSQUARTER
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.
Example
Previous Quarter = CALCULATE(SUM(Orders[Sales]), PREVIOUSQUARTER(Dim_Date[Date]))
PREVIOUSYEAR
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.
Example
Previous Year = CALCULATE(SUM(Orders[Sales]), PREVIOUSYEAR(Dim_Date[Date]))
NEXTDAY
Returns a table that contains a column of all dates from the next day, based on the
first date specified in the dates column in the current context.
Example
Next Day = CALCULATE ([Sum of Sales], NEXTDAY(Dim_Date[Date]))
NEXTMONTH
Returns a table that contains a column of all dates from the next month, based on the
first date in the dates column in the current context.
Example
Next Month = CALCULATE ([Sum of Sales], NEXTMONTH(Dim_Date[Date]))
NEXTQUARTER
Returns a table that contains a column of all dates in the next quarter, based on the
first date specified in the dates column, in the current context.
Example
Next Quarter = CALCULATE ([Sum of Sales], NEXTQUARTER(Dim_Date[Date]))
NEXTYEAR
www.abtrainings.com
Power BI Analytics Benchmark (AB) Trainings
Returns a table that contains a column of all dates in the next year, based on the first
date in the dates column, in the current context.
Example
Next Year = CALCULATE ([Sum of Sales], NEXTYEAR(Dim_Date[Date]))
SAMEPERIODLASTYEAR
Returns a table that contains a column of dates shifted one year back in time from the
dates in the specified dates column, in the current context.
Example
www.abtrainings.com
Power BI Analytics Benchmark (AB) Trainings
MOM Growth
Sum of Sales = SUM(Orders[Sales])
Last Month Sales = CALCULATE(SUM(Orders[Sales]), PREVIOUSMONTH(Dim_Date[Date]))
% MOM = DIVIDE ([Sum of Sales], [Last Month Sales])
www.abtrainings.com