Sub topic 6
Adding year, quarter, month, and week columns
This chapter assumes you can create a calculated table in Power BI Desktop and write basic DAX. It also assumes you already have a one-column table of consecutive dates, built with CALENDAR or with Power Query's List.Dates. Here you add the calendar attributes that report authors group and filter by.
Why the columns matter
A date column alone can only be shown by day. To show sales by month, compare quarters, or filter to one year, you need columns that hold each date's year, quarter, month, and week. Putting these columns in the date table has three advantages:
- Every report uses the same definitions. "Q3" means the same thing in every visual.
- The columns live on the dimension table, so one slicer filters every fact table related to it.
- Time intelligence functions work on the date column, and the extra columns give you labels and axes for the results.
Each attribute usually needs two columns: a text label for display (Jan) and a number for ordering (1). Text sorts alphabetically, so Apr would come before Jan. The next chapter shows how to fix that with Sort by column. This chapter builds both columns so the fix is possible.
Building the columns in DAX
ADDCOLUMNS wraps the CALENDAR table and adds one column per name and expression pair. Inside it, [Date] refers to the current row's date.
Date =
VAR Base =
CALENDAR ( DATE ( 2020, 1, 1 ), DATE ( 2026, 12, 31 ) )
RETURN
ADDCOLUMNS (
Base,
"Year", YEAR ( [Date] ),
"Quarter Number", QUARTER ( [Date] ),
"Quarter", "Q" & QUARTER ( [Date] ),
"Year-Quarter", YEAR ( [Date] ) & "-Q" & QUARTER ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Month", FORMAT ( [Date], "MMM" ),
"Month Name", FORMAT ( [Date], "MMMM" ),
"Year-Month", FORMAT ( [Date], "yyyy-MM" ),
"Year-Month Number", YEAR ( [Date] ) * 100 + MONTH ( [Date] ),
"Day of Week Number", WEEKDAY ( [Date], 2 ),
"Day of Week", FORMAT ( [Date], "ddd" ),
"ISO Week", WEEKNUM ( [Date], 21 ),
"ISO Year", YEAR ( [Date] + 4 - WEEKDAY ( [Date], 2 ) ),
"Week Start", [Date] - WEEKDAY ( [Date], 2 ) + 1
)The calendar bounds are hard-coded here. Chapter 4 showed how to derive them from the fact table, and you can swap that in for Base.
What each column is for
| Column | Type | Example for 2026-03-15 | Use |
|---|---|---|---|
| Year | Whole number | 2026 | Slicers, axis, filters |
| Quarter Number | Whole number | 1 | Sort key for Quarter |
| Quarter | Text | Q1 | Axis label |
| Year-Quarter | Text | 2026-Q1 | Axis that spans several years |
| Month Number | Whole number | 3 | Sort key for Month |
| Month | Text | Mar | Axis label |
| Year-Month | Text | 2026-03 | Axis that spans several years |
| Year-Month Number | Whole number | 202603 | Numeric month index |
| ISO Week | Whole number | 11 | Weekly reports |
| Week Start | Date | 2026-03-09 | Axis that shows one point per week |
Year-Month in the yyyy-MM format sorts correctly as plain text, because the year comes first and the month is zero-padded. You can use it as an axis without any sort setup. Month, Quarter, and Day of Week do not sort correctly as text, so they need their number columns.
Why `Year-Month` matters
A chart that groups only by Month merges every January in the data into one point. A chart on Year-Month keeps January 2025 and January 2026 apart. Use the month label alone only when you want a seasonal view across years, or when a Year filter is in place.
Weeks are not like the other levels
Years, quarters, and months nest cleanly. Weeks do not, because a week can cross a month boundary and a year boundary. Pick a week definition on purpose.
| Approach | DAX | Week 1 is | Week starts on |
|---|---|---|---|
| US style | `WEEKNUM ( [Date], 1 )` | The week containing January 1 | Sunday |
| Monday-start | `WEEKNUM ( [Date], 2 )` | The week containing January 1 | Monday |
| ISO 8601 | `WEEKNUM ( [Date], 21 )` | The week containing the first Thursday | Monday |
The second argument of WEEKNUM is the return type. Types 1 and 2 can give a week 1 with only one or two days in it. ISO weeks always run Monday to Sunday and always have seven days in the year they belong to.
The ISO year problem
With ISO weeks, 2026-01-01 is a Thursday, so it falls in ISO week 1 of 2026. But 2027-01-01 is a Friday, so it belongs to ISO week 53 of 2026. If you group by Year and ISO Week, that January 1 date lands in week 53 of 2027, next to the wrong days. This is why the table has an ISO Year column.
The expression [Date] + 4 - WEEKDAY ( [Date], 2 ) finds the Thursday of the current week. WEEKDAY ( [Date], 2 ) returns 1 for Monday through 7 for Sunday. Adding 4 and subtracting the weekday number moves any date to that week's Thursday. The year of that Thursday is the ISO year.
For weekly reports, group by ISO Year and ISO Week, or use Week Start. A date-typed Week Start column is the simplest option, because it sorts correctly and has no year ambiguity.
Building the columns in Power Query
If you built the date table in Power Query, add the columns there with Table.AddColumn. The columns are computed when the data refreshes and are stored with the table.
let
StartDate = #date(2020, 1, 1),
EndDate = #date(2026, 12, 31),
Dates = List.Dates(StartDate, Duration.Days(EndDate - StartDate) + 1, #duration(1, 0, 0, 0)),
AsTable = Table.FromList(Dates, Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),
Typed = Table.TransformColumnTypes(AsTable, {{"Date", type date}}),
AddYear = Table.AddColumn(Typed, "Year", each Date.Year([Date]), Int64.Type),
AddQuarterNumber = Table.AddColumn(AddYear, "Quarter Number", each Date.QuarterOfYear([Date]), Int64.Type),
AddQuarter = Table.AddColumn(AddQuarterNumber, "Quarter", each "Q" & Text.From(Date.QuarterOfYear([Date])), type text),
AddMonthNumber = Table.AddColumn(AddQuarter, "Month Number", each Date.Month([Date]), Int64.Type),
AddMonth = Table.AddColumn(AddMonthNumber, "Month", each Date.ToText([Date], "MMM"), type text),
AddYearMonth = Table.AddColumn(AddMonth, "Year-Month", each Date.ToText([Date], "yyyy-MM"), type text),
AddDayNumber = Table.AddColumn(AddYearMonth, "Day of Week Number", each Date.DayOfWeek([Date], Day.Monday) + 1, Int64.Type),
AddWeekStart = Table.AddColumn(AddDayNumber, "Week Start", each Date.StartOfWeek([Date], Day.Monday), type date)
in
AddWeekStartTwo differences from the DAX version:
Date.DayOfWeekcounts from 0, so the query adds 1 to match the DAXWEEKDAY ( [Date], 2 )numbering.Date.WeekOfYearhas no ISO option. It numbers week 1 as the week containing January 1. If you need ISO week numbers, build the table in DAX, or compute the Thursday of each week in M and derive the week from it.
The last argument of Table.AddColumn is the column type. Setting it explicitly avoids a column of type any, which Power BI would load as text and which then breaks numeric sorting.
Choosing DAX or Power Query for the columns
| Consideration | DAX calculated table | Power Query |
|---|---|---|
| Recalculated | When the model refreshes | When the query refreshes |
| Culture-dependent labels | `FORMAT` uses the model's locale | `Date.ToText` uses the query's culture |
| ISO week | Built in with `WEEKNUM ( ..., 21 )` | Needs custom logic |
| Reuse in other tools | Power BI model only | Can be reused in dataflows |
Pick one place for the columns and keep them there. Splitting some columns across both makes the table hard to maintain.
Practical details
Data types and summarization
Year and the number columns are whole numbers. Power BI treats numeric columns as measures by default, which can place Year in a visual's Values well and sum it into a meaningless total. In the Column tools tab, set Summarize by to Don't summarize for Year, Quarter Number, Month Number, ISO Week, and similar columns.
Hiding helper columns
After you set up sorting in the next chapter, hide the number columns so report authors use only the labels. Hiding a column does not stop it from sorting another column.
Language and format strings
FORMAT ( [Date], "MMM" ) returns names in the language of the machine or service that evaluates it. A report authored in an English-language Desktop and refreshed in a service with a different locale can show janv. instead of Jan. If you need fixed English labels, use a lookup with SWITCH ( MONTH ( [Date] ), 1, "Jan", 2, "Feb", ... ) or an explicit mapping table.
Keep time out of the date column
CALENDAR returns whole dates only. If the fact table has datetime values, convert them to dates before relating them, or the relationship will match no rows. The relationship chapter covers this.
Checking the result
- Open the Table view and select the
Datetable. - Confirm that the first row is January 1 of your first year and the last row is December 31 of your last year.
- Scroll to a year boundary and check
ISO WeekandISO Year. For example, 2027-01-01 should showISO Week53 andISO Year2026. - Put
Monthon a table visual and notice that the order is alphabetical. That is expected until you apply Sort by column.
Exercise
A weekly chart uses Year and ISO Week as its axis. In the first days of January 2027, the chart shows a point labelled "2027, week 53". What is wrong, and which column or columns fix it?
Show answer
ISO week 53 of 2026 runs through January 3, 2027, so those dates belong to ISO year 2026, but the calendar Year column says 2027. Group by ISO Year and ISO Week instead of Year and ISO Week. Alternatively, use the Week Start date column, which has no year ambiguity.
Exercise
You add a Month column with FORMAT ( [Date], "MMM" ) and a Month Number column with MONTH ( [Date] ). A column chart shows the months as Apr, Aug, Dec, Feb, and so on. Which column do you need to apply, and what must you configure next?
Show answer
The month label sorts as text, so the chart is alphabetical. Month Number holds the order, so set Month to Sort by column Month Number. That setting is covered in the next chapter.