1. Introduction to DAX

Subtitles Enabled

Sign up for a free trial to access more free content.

Free trial

Essential DAX Functions and Concepts

12 lessons , 4 exercises , 1 exam

Preview Course


In this lesson, we will introduce DAX, discuss why Power Pivot needs its own formula language and introduce the dataset for this course.

Lesson Notes

What is DAX

  • Data Analysis Expressions, or DAX, is the formula language used in Power Pivot
  • When conducting analysis in the Excel data model, you use DAX formulas

Why does Power Pivot not just use normal Excel formulas?

  • Normal Excel data is generally in an unstructured format
  • Excel formulas are designed to work with cells or ranges of cells
  • However, the Power Pivot data model is made up of structured tables and columns
  • DAX is designed to work with this structured data model


In the previous course, we introduced DAX, the language used to create formulas and functions in Power Pivot.

In this course, we'll look at common areas of analysis, such as date functions and time intelligence, as well as more advanced topics, such as filters and contexts.

In this first lesson, we'll look at date functions.

The primary use of date functions in DAX is to extract or identify elements of a date field.

Date functions in DAX are very similar to date functions in Excel.

We'll start by opening the same pharma data set that we used in previous Power Pivot courses.

As we can see, our data set includes one Date column, representing the date on which we sold a specific product to a specific customer.

Let's create a calculated column, called Year, that will extract just the Year value from every Date column.

We can do this using a function called YEAR.

The YEAR function takes the Date column as its argument.

As we can see, it produces a column showing the year for every date in the data set.

Similar functions are available for month, day, hour, second, and almost any other aspect of date/time data you can think of.

While extracting the year might not seem particularly useful, there are date functions that extract less obvious information from a date field.

For example, we can get the week number from our date field by using the function WEEKNUM.

We'll create a new column, call it Week Number, and use the WEEKNUM formula on the Date column.

This could be useful if we want to analyze our data on a weekly basis.

Another interesting date function is TODAY.

This will return the current day.

Let's use this to examine the number of days since the last sale for each customer.

We'll create another calculated column and call it Days Since Sale.

Fortunately, DAX allows us to use dates in simple arithmetic, so we'll do it here.

We'll find the days since the sale for each row by subtracting the value in the date field from TODAY.

This returns the number of days from each specific sale. However, the values are formatted as dates.

We want these values formatted as numbers.

To fix this, we'll navigate to the Formatting area on the Home tab, select Data Type and then Decimal Number.

Now each row shows the number of days since the transaction.

Let's use this new column in a PivotTable.

We'll create a PivotTable and put it on the existing blank worksheet.

We'll add Customer ID and Days Since Sale to the table.

We want to see the minimum days since sale, which will tell us the number of days since the most recent sale for each customer.

Therefore, we'll select the arrow by Sum of Days Since Sale, go to Value Field Settings, and select Min.

We can see that most customers made a purchase on the last day of the data set, but a few customers have not made a purchase for some time.

We could use this information as a starting point to investigate why customers stop buying the company's products.

Finally, let's find the date of the most recent sale for each product.

To do this, we'll use a function called LASTDATE.

We'll create a measure, call it Last Sale, and enter the LASTDATE function, applied to the Date column.

We'll then select OK to create the measure.

Let's remove this column from the PivotTable and create a new PivotTable on a new sheet.

We'll add the Product Name field to the table, along with the Last Sale measure.

We can see that the most recent sale for most products was September 2017.

However, Slintara had its last sale in September 2015.

Again, this could be used to start an investigation.

Maybe the product has been discontinued.

Let's stop the lesson here.

As we've seen, date functions are pretty easy to work with and allow you to extract virtually any possible element from a date field.

In the next lesson, we'll learn about date tables, an essential part of time intelligence analysis in DAX.