In this article, we will explore how to use the Power BI DAX function YEAR and provide some examples to help you get started.
What is the Power BI DAX function YEAR?
The Power BI DAX function YEAR is a date and time function that extracts the year from a given date. This function takes a date column or a date-time column as input and returns the year as an integer.
Syntax of the Power BI DAX function YEAR
The syntax of the Power BI DAX function YEAR is as follows:
The ❰date❱ argument is the date column or date-time column from which you want to extract the year.
Examples of using the Power BI DAX function YEAR
Let's look at some examples of how to use the Power BI DAX function YEAR.
Example 1: Extracting the year from a date column
Suppose you have a table that contains a date column, and you want to extract the year from that column. You can use the following DAX formula:
Here, Table1 is the name of the table, and Date is the name of the date column.
Example 2: Extracting the year from a date-time column
Suppose you have a table that contains a date-time column, and you want to extract the year from that column. You can use the following DAX formula:
Here, Table1 is the name of the table, and DateTime is the name of the date-time column.
Example 3: Using the YEAR function with other functions
You can also use the YEAR function in combination with other functions. For example, suppose you have a table that contains a date column, and you want to calculate the total sales for each year. You can use the following DAX formula:
YEAR(Table1[Date]) = 2022
Here, SUMX is a function that calculates the sum of an expression for each row in a table, FILTER is a function that filters a table based on a condition, and Table1 is the name of the table.
The formula calculates the total sales for the year 2022 by first filtering the table to include only the rows where the year is 2022, and then summing up the sales for those rows.
The Power BI DAX function YEAR is a powerful tool that allows you to extract the year from a date. It can be particularly useful when working with large data sets, as it can save you a lot of time and effort. By using the examples provided in this article, you can start using the YEAR function in your own Power BI reports and dashboards.
Power BI DAX Training Courses by G Com Solutions (0800 998 9248)
Power BI DAX Intensive Training Course£1,050.00 – £26,550.00
Power BI DAX Introduction£395.00 – £9,750.00
Power BI DAX Intermediate£395.00 – £9,750.00
Power BI DAX Advanced£395.00 – £9,750.00