13.3Working with dates and times
Your data almost always has dates. These functions cut them up, build them and shift them. They return a single value, and are often used in the calculated columns of the calendar. The examples start from the date of sale V001, 1/15/2024.
13.3.1YEAR, QUARTER, MONTH and DAY
In Excel
| DAX | YEAR | QUARTER | MONTH | DAY |
|---|---|---|---|---|
| Excel | YEAR | ROUNDUP(MONTH(d)/3,0) | MONTH | DAY |
| Match |
You need them when you want part of a date, the year to compare 2024 and 2025, or the month. That is how the “Year” or Month columns of a Calendar table are built.
They return the year, the quarter, the month and the day of a date, like YEAR, MONTH and DAY in Excel.
| The year | YEAR( <date> ) |
|---|---|
| The quarter | QUARTER( <date> ) |
| The month | MONTH( <date> ) |
| The day | DAY( <date> ) |
Each one expects a single argument, a date, most often a column of dates written with its table, like Sales[Date].
On the V001 row, dated 1/15/2024:
- YEAR( Sales[Date] ) returns 2024.
- QUARTER( Sales[Date] ) returns 1.
- MONTH( Sales[Date] ) returns 1.
- DAY( Sales[Date] ) returns 15.
| [Sale ID] | [Date] | [Year] | [Quarter] | [Month] | [Day] | |
|---|---|---|---|---|---|---|
| 1 | V001 | 1/15/2024 | 2024 | 1 | 1 | 15 |
| 2 | V002 | 3/8/2024 | 2024 | 1 | 3 | 8 |
| 3 | V003 | 5/20/2024 | 2024 | 2 | 5 | 20 |
| 4 | V004 | 9/12/2024 | 2024 | 3 | 9 | 12 |
| 5 | V005 | 11/25/2024 | 2024 | 4 | 11 | 25 |
| 6 | V006 | 1/10/2025 | 2025 | 1 | 1 | 10 |
| 7 | V007 | 2/18/2025 | 2025 | 1 | 2 | 18 |
| 8 | V008 | 3/27/2025 | 2025 | 1 | 3 | 27 |
| 9 | V009 | 5/6/2025 | 2025 | 2 | 5 | 6 |
| 10 | V010 | 7/14/2025 | 2025 | 3 | 7 | 14 |
| 11 | V011 | 9/30/2025 | 2025 | 3 | 9 | 30 |
| 12 | V012 | 12/2/2025 | 2025 | 4 | 12 | 2 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
Practice
Each exercise is solved with the function you just discovered. Two exercises per function, a direct use and a combined use, from easiest to hardest, on data other than the course data. Pick the right formula out of five.
Direct useCalculated columnDifficulty
A library records the date each reader joined, in the “Memberships” table. Add the calculated column “Year” to the “Memberships” table, the year the reader joined.
Memberships Reader Joined Lina 2/14/2025 Marc 9/3/2026 Which formula should you write for “Year”?
Combined useCalculated columnDifficulty
The library tells its long-standing readers, who joined before 2026, from the new ones. Add the calculated column “Status” to the “Memberships” table, which shows “Existing” or “New”.
Memberships Reader Joined Lina 2/14/2025 Marc 9/3/2026 Direct useCalculated columnDifficulty
A hotel wants to count its arrivals per quarter. Add the calculated column “Quarter” to the “Stays” table, the quarter of the arrival date.
Stays Guest Arrival Alma 1/2/2026 Bilal 5/12/2026 Chloé 11/28/2026 Combined useCalculated columnDifficulty
The hotel does its accounts by half-year. Add the calculated column “Half Year” to the “Stays” table, 1 or 2.
Stays Guest Arrival Alma 1/2/2026 Bilal 5/12/2026 Chloé 11/28/2026 Direct useCalculated columnDifficulty
A school prepares the birthdays of each month. Add the calculated column “Birth Month” to the “Students” table, the number of the month.
Students Student Birth Date Alma 3/21/2016 Bilal 10/8/2015 Chloé 3/30/2016 Combined useMeasureDifficulty
The school wants to prepare the March birthday party. Write the “Born in March” measure, the number of students of the “Students” table born in March, whatever the year. You will read it in a card.
Students Student Birth Date Alma 3/21/2016 Bilal 10/8/2015 Chloé 3/30/2016 Direct useCalculated columnDifficulty
A sports club collects the fee every month, on the same day as the start of the subscription. Add the calculated column “Debit Day” to the “Subscriptions” table.
Subscriptions Member Start Inès 1/14/2026 Hugo 2/3/2026 Combined useCalculated columnDifficulty
The club collects in two waves, on the 15th for the subscriptions started in the first half of the month, on the 30th for the others. Add the calculated column “Wave” to the “Subscriptions” table, which shows “On the 15th” or “On the 30th”.
Subscriptions Member Start Inès 1/14/2026 Hugo 2/3/2026 Jade 1/22/2026
The rest of this lesson is part of izyDAX Pro
You have just read the first section. The next 5, their animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.