Chapter 8: Date & Time Functions 1/2: Basic Functions 251
The calculated column that contains the returned month number is often added to
Column Labels or Row Labels in a pivot table. It’s frequently combined with a year
column and a quarter column to give drill-down on dates. There is, however, a potential
drawback—the months appear as numbers rather than month names. Many users prefer
to see the month names. Unfortunately, there is no DAX function in this first release of
PowerPivot to give you the month name directly. There are at least two solutions, if the
month name is not already part of your source data. One, you can write your own DAX
formula to generate the month name. It might begin something like the following:
=IF(MONTH(Orders[OrderDate])=1,"January",
IF(MONTH(Orders[OrderDate])=2,"February",
and so on. Alternatively, you could do this:
=IF(MONTH(Orders[OrderDate])=1,"Jan",
IF(MONTH(Orders[OrderDate])=2,"Feb",
and so on.
Two, you can write a query when you import the data, if it’s from a suitable source.
For a SQL Server source, you might try one of these:
select datename(mm,orderdate) as MonthName from orders
select left(datename(mm,orderdate),3) as MonthName from orders
This, in turn, raises another interesting problem. If you add the month name to Row
Labels or Column labels in a pivot table, the month names are sorted alphabetically
(April, August, and so on). Fortunately, there is a GUI solution. First, right-click on
a month name in the pivot table. Choose Sort, More Sort Options to open the Sort
dialog. In this dialog, click More Options to open the More Sort Options dialog. In
this second dialog, under AutoSort, turn off Sort Automatically Every Time the Report
Is Updated. Then, from the First Key sort order drop-down, choose the entry beginning
Jan or January (whichever is appropriate). Click OK twice to exit the two dialogs.
Right-click once again on the month name in the pivot table, and choose Sort, followed
by Sort A to Z.
NOW()
NOW() returns the current date and time. This is in contrast with TODAY(), which only
returns the date.
The example is for a calculated column in any table.