Extracting Date Components in Power BI Using DAX

 

Extracting Date Components in Power BI Using DAX (Year, Month, Quarter, Day, and Weekday)

Introduction: 

In Power BI Desktop, datasets often contain a Date column that stores complete date information. However, for proper analysis and dashboard creation, analysts usually need separate components of the date such as Year, Month, Quarter, Day, Day Name, Month Name, and Weekday.

Power BI allows us to create these values using DAX (Data Analysis Expressions) by adding a New Column in the dataset.


Step 1: Open Power BI Desktop

Open Power BI Desktop and load the dataset that contains the Date column.

Example dataset table name: 

Tesla_dataset - Download Dataset

Date column:

Date


Step 2: Go to Data View

On the left side panel, click the Data View icon (table icon).

This view shows the dataset in tabular format where you can create and view calculated columns.


Step 3: Select the Dataset Table

From the Fields pane, select the table that contains the date column.

Example:

Tesla_dataset

Once the table is selected, Power BI activates the Table Tools tab on the top ribbon.


Step 4: Create a New Column

To create a calculated column:

  1. Select the dataset table.

  2. Go to the Table Tools tab.

  3. Click New Column.

A formula bar will appear where you can write the DAX expression.


Step 5: Write the DAX Formula

In the formula bar, write the column name followed by the formula.

Example:

Year = YEAR(Tesla_dataset[Date])

Press Enter.

Power BI will create the column and fill the values automatically.


General Syntax of a New Column

Column Name = DAX Formula

Example:

Month = MONTH(Tesla_dataset[Date])

Creating Date-Based Columns Using DAX


1 Creating Year Column

DAX Formula

Year = YEAR(Tesla_dataset[Date])

Explanation

The YEAR() function extracts the year part from the date.

Example Output

DateYear
10-03-20262026

2 Creating Month Number Column

DAX Formula

Month Number = MONTH(Tesla_dataset[Date])

Explanation

The MONTH() function returns the month number (1–12).

Example

DateMonth Number
10-03-20263

3 Creating Month Name Column

DAX Formula

Month Name = FORMAT(Tesla_dataset[Date], "MMMM")

Explanation

The FORMAT() function converts the date into text format.

The option "MMMM" tells Power BI to display the full month name.

Example

DateMonth Name
10-03-2026March

Other format options include:

FormatOutput Example
"MMM"Mar
"MMMM"March
"MM"03

So the format option determines how the month will appear in the column.


4 Creating Quarter Column

DAX Formula

Quarter = "Q" & FORMAT(Tesla_dataset[Date], "Q")

Explanation

The FORMAT() function with "Q" returns the quarter number.

Example

DateQuarter
10-03-2026Q1

Quarter classification:

QuarterMonths
Q1Jan – Mar
Q2Apr – Jun
Q3Jul – Sep
Q4Oct – Dec

5 Creating Day Column

DAX Formula

Day = DAY(Tesla_dataset[Date])

Explanation

The DAY() function extracts the day number from the date.

Example

DateDay
10-03-202610

6 Creating Day Name Column

DAX Formula

Day Name = FORMAT(Tesla_dataset[Date], "dddd")

Explanation

The FORMAT() function converts the date into the name of the day.

The option "dddd" displays the full day name.

Example

DateDay Name
10-03-2026Tuesday

Other day format options include:

FormatOutput
"ddd"Tue
"dddd"Tuesday

So the format parameter determines how the day information appears in the dataset.


7 Creating Weekday Number Column

DAX Formula

Week = WEEKDAY(Tesla_dataset[Date])

Explanation

The WEEKDAY() function returns the day of the week as a number.

Default numbering:

NumberDay
1Sunday
2Monday
3Tuesday
4Wednesday
5Thursday
6Friday
7Saturday

Example

DateWeek
10-03-20263

Here 3 represents Tuesday.


Changing the Weekday Start

If Monday should be considered the first day of the week, use:

Week = WEEKDAY(Tesla_dataset[Date],2)

New numbering:

NumberDay
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday
7Sunday


Why FORMAT Options Are Important

Options like "MMMM" or "dddd" control how the information appears in the dataset.

For example:

FunctionResult
FORMAT(Date,"MM")03
FORMAT(Date,"MMM")Mar
FORMAT(Date,"MMMM")March
FORMAT(Date,"ddd")Tue
FORMAT(Date,"dddd")Tuesday

टिप्पणी पोस्ट करा

0 टिप्पण्या