Skip to main content

Date and Time Functions

DAX (Data Analysis Expressions) in Power BI includes a comprehensive set of date and time functions. These functions are essential for creating calculated columns and measures that involve dates and times, enabling powerful time-based analysis and insights. Here's an overview of some key DAX date and time functions:


1. DATE

Syntax:

DATE(year, month, day)

Description:

Creates a date value from year, month, and day components.

Example:

DATE(2023, 5, 20)  -- Returns: May 20, 2023



2. TIME

Syntax:

TIME(hour, minute, second)

Description:

Creates a time value from hour, minute, and second components.

Example:

TIME(14, 30, 0)  -- Returns: 2:30 PM


3. TODAY

Syntax:

TODAY()

Description:

Returns the current date.

Example:

TODAY()  -- Returns: Current date


4. NOW

Syntax:

NOW()

Description:

Returns the current date and time.

Example:

NOW()  -- Returns: Current date and time


5. YEAR

Syntax:

YEAR(<date>)

Description:

Returns the year component of a date.

Example:

YEAR(DATE(2023, 5, 20))  -- Returns: 2023


6. MONTH

Syntax:

MONTH(<date>)

Description:

Returns the month component of a date.

Example:

MONTH(DATE(2023, 5, 20))  -- Returns: 5


7. DAY

Syntax:

DAY(<date>)

Description:

Returns the day component of a date.

Example:

DAY(DATE(2023, 5, 20))  -- Returns: 20


8. HOUR

Syntax:

HOUR(<datetime>)

Description:

Returns the hour component of a time value.

Example:

HOUR(TIME(14, 30, 0))  -- Returns: 14


9. MINUTE

Syntax:

MINUTE(<datetime>)

Description:

Returns the minute component of a time value.

Example:

MINUTE(TIME(14, 30, 0))  -- Returns: 30


10 . SECOND

Syntax:

SECOND(<datetime>)

Description:

Returns the second component of a time value.

Example:

SECOND(TIME(14, 30, 0))  -- Returns: 0


11. DATEDIFF

Syntax:

DATEDIFF(<start_date>, <end_date>, <interval>)

Description:

Returns the difference between two dates in the specified interval (SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR).

Example:

DATEDIFF(DATE(2023, 5, 1), DATE(2023, 5, 20), DAY)  -- Returns: 19


12. EOMONTH

Syntax:

EOMONTH(<start_date>, <months>)

Description:
Returns the last day of the month, offset by a specified number of months.

Example:

EOMONTH(DATE(2023, 5, 20), 1)  -- Returns: June 30, 2023


13. WEEKDAY

Syntax:

WEEKDAY(<date>, [return_type])

Description:

Returns the day of the week as an integer (1-7), with an optional return_type to specify the start of the week.

Example:

WEEKDAY(DATE(2023, 5, 20))  -- Returns: 7 (Saturday, assuming the week starts on Sunday)


14. WEEKNUM

Syntax:

WEEKNUM(<date>, [return_type])

Description:

Returns the week number for a given date, with an optional return_type to specify the start of the week.

Example:

WEEKNUM(DATE(2023, 5, 20))  -- Returns: 20 (20th week of the year)


15. FORMAT

Syntax:

FORMAT(<value>, <format_string>)

Description:

Converts a value to text according to the specified format.

Example:

FORMAT(TODAY(), "DD/MM/YYYY")  -- Returns: Formatted date as "20/05/2023"


DAX date and time functions are powerful tools for manipulating and analyzing dates and times in Power BI. They enable robust time-based calculations and are essential for any time intelligence analysis. By mastering these functions, you can enhance your reports and dashboards with accurate and insightful date and time metrics.

Comments

Popular posts from this blog

Power BI tenant settings and admin portal

As of my last update, Power BI offers a dedicated admin portal for managing settings and configurations at the tenant level. Here's an overview of Power BI tenant settings and the admin portal: 1. Power BI Admin Portal: Access : The Power BI admin portal is accessible to users with admin privileges in the Power BI service. URL : You can access the admin portal at https://app.powerbi.com/admin-portal . 2. Tenant Settings: General Settings : Configure general settings such as tenant name, regional settings, and language settings. Tenant Administration : Manage user licenses, permissions, and access rights for Power BI within the organization. Usage Metrics : View usage metrics and reports to understand how Power BI is being used across the organization. Service Health : Monitor the health status of the Power BI service and receive notifications about service incidents and outages. Audit Logs : Access audit logs to track user activities, access requests, and administrative actions wit...

Using bookmarks and buttons for navigation

Using bookmarks and buttons for navigation in Power BI allows you to create interactive experiences within your reports, guiding users through different views and sections. Let's walk through how to use bookmarks and buttons for navigation: Step 1: Create Bookmarks Navigate to the "View" tab : Open your report in Power BI Desktop and navigate to the "View" tab. Create Bookmarks : Select the elements (visuals, slicers, shapes, etc.) that you want to bookmark. Click on the "Bookmark" button in the "View" tab or right-click and select "Add bookmark". Name your bookmark and ensure the "Data" and "Display" options are selected if you want to capture filter states and visual display states. Repeat for Additional Views : Create bookmarks for each view or section of your report that you want to navigate to. Step 2: Create Buttons Insert Buttons : Go to the "Home" tab and click on the "Buttons" dropdow...

Understanding the Power BI ecosystem and workflow

Understanding the Power BI ecosystem and workflow involves getting familiar with the various components of Power BI and how they interact to provide a comprehensive data analysis and visualization solution. Here's a detailed explanation: Power BI Ecosystem The Power BI ecosystem consists of several interconnected components that work together to enable users to connect to data sources, transform and model data, create visualizations, and share insights. The main components are: Power BI Desktop Power BI Service Power BI Mobile Power BI Gateway Power BI Report Server Power BI Embedded PowerBI Workflow Here’s a typical workflow in the Power BI ecosystem: Step 1: Connect to Data Sources Power BI Desktop:  Connect to various data sources like Excel, SQL databases, cloud services, and more. Power BI Gateway:  If using on-premises data sources, install and configure the gateway for secure data transfer. Step 2: Data Transformation and Modeling Power BI Desktop:  Use Power Query...