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

TechUplift: Elevating Your Expertise in Every Click

  Unlock the potential of data with SQL Fundamental: Master querying, managing, and manipulating databases effortlessly. Empower your database mastery with PL/SQL: Unleash the full potential of Oracle databases through advanced programming and optimization. Unlock the Potential of Programming for Innovation and Efficiency.  Transform raw data into actionable insights effortlessly. Empower Your Data Strategy with Power Dataware: Unleash the Potential of Data for Strategic Insights and Decision Making.

SQL Fundamentals

SQL, or Structured Query Language, is the go-to language for managing relational databases. It allows users to interact with databases to retrieve, manipulate, and control data efficiently. SQL provides a standardized way to define database structures, perform data operations, and ensure data integrity. From querying data to managing access and transactions, SQL is a fundamental tool for anyone working with databases. 1. Basics of SQL Introduction : SQL (Structured Query Language) is used for managing and manipulating relational databases. SQL Syntax : Basic structure of SQL statements (e.g., SELECT, INSERT, UPDATE, DELETE). Data Types : Different types of data that can be stored (e.g., INTEGER, VARCHAR, DATE). 2. SQL Commands DDL (Data Definition Language) : CREATE TABLE : Define new tables. ALTER TABLE : Modify existing tables. DROP TABLE : Delete tables. DML (Data Manipulation Language) : INSERT : Add new records. UPDATE : Modify existing records. DELETE : Remove records. DQL (Da...

DAX Functions

These are just some of the many DAX functions available in Power BI. Each  function serves a specific purpose and can be used to perform a wide range of calculations and transformations on your data. Aggregation Functions: SUM : Calculates the sum of values. AVERAGE : Calculates the arithmetic mean of values. MIN : Returns the smallest value in a column. MAX : Returns the largest value in a column. COUNT : Counts the number of rows in a table or column. COUNTA : Counts the number of non-blank values in a column. DISTINCTCOUNT : Counts the number of unique values in a column. Logical Functions: IF : Returns one value if a condition is true and another value if it's false. AND : Returns TRUE if all the conditions are true, otherwise FALSE. OR : Returns TRUE if any of the conditions are true, otherwise FALSE. NOT : Returns the opposite of a logical value. Text Functions: CONCATENATE : Concatenates strings together. LEFT : Returns the leftmost characters from a text string. RIGHT : Ret...