05.1The calculated column
At times you will want one more piece of information on each row of a table, like a category or a calculation made row by row. That is what the calculated column is for.
05.1.1Adding a calculated column to a table
You can add a column to a physical table as well as to a calculated table. That is the calculated column.
At first, all the columns of a calculated table come from its formula. For Calendar, CALENDARAUTO created the Date column. Once the table exists, you can add other columns to it in two ways:
- In DAX, by changing its formula, for example with ADDCOLUMNS.
- Through the Power BI interface, with the New column button. In that case, the formula of the table does not change.
To find this button, in Table view, first choose the table in the Data pane. Then click New column, in the Table tools tab of the ribbon. In Report view, the same button sits in the Modeling tab. A right-click on the table, in the Data pane, also offers New column.
A physical table, like Sales, has no DAX formula to change. To add a calculated column to it in DAX, you therefore go through the New column button.
05.1.2Why create a calculated column?
Several reasons can lead you to create a calculated column. Take the calculated table Calendar. You are going to add several columns to it, needed to analyze the sales properly.
Data needs landmarks in time to make sense. So you are going to create a calculated column for each of these periods, the year, the quarter, the month and the week. With the New column button, you write:
In WEEKNUM, the 2 makes the week start on Monday. Each date thus gets its year, its quarter, its month and its week:
Week = WEEKNUM( Calendar[Date], 2 )| Date | Year | Quarter | Month | Week |
|---|---|---|---|---|
| 1/1/2024 | 2024 | 1 | 1 | 1 |
| 1/2/2024 | 2024 | 1 | 1 | 1 |
| 1/3/2024 | 2024 | 1 | 1 | 1 |
| 1/4/2024 | 2024 | 1 | 1 | 1 |
| 1/5/2024 | 2024 | 1 | 1 | 1 |
| 1/6/2024 | 2024 | 1 | 1 | 1 |
| 1/7/2024 | 2024 | 1 | 1 | 1 |
| 1/8/2024 | 2024 | 1 | 1 | 2 |
| 1/9/2024 | 2024 | 1 | 1 | 2 |
| 1/10/2024 | 2024 | 1 | 1 | 2 |
| 1/11/2024 | 2024 | 1 | 1 | 2 |
| 1/12/2024 | 2024 | 1 | 1 | 2 |
| 1/13/2024 | 2024 | 1 | 1 | 2 |
| 1/14/2024 | 2024 | 1 | 1 | 2 |
| 1/15/2024 | 2024 | 1 | 1 | 3 |
| 1/16/2024 | 2024 | 1 | 1 | 3 |
| 1/17/2024 | 2024 | 1 | 1 | 3 |
| 1/18/2024 | 2024 | 1 | 1 | 3 |
| 1/19/2024 | 2024 | 1 | 1 | 3 |
| 1/20/2024 | 2024 | 1 | 1 | 3 |
| 1/21/2024 | 2024 | 1 | 1 | 3 |
| 1/22/2024 | 2024 | 1 | 1 | 4 |
| 1/23/2024 | 2024 | 1 | 1 | 4 |
| 1/24/2024 | 2024 | 1 | 1 | 4 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
See easier-to-read landmarks, with FORMAT
The functions above return numbers. January is month 1, the first week of the year is week 1, and so on. In a visual, these numbers are not very handy, and they say little. Yet, if you add columns to a calendar, it is precisely to find the periods more easily.
FORMAT writes the date the way you read it, following a pattern placed between quotation marks. The letters of the pattern are:
- d for day
- m for month
- y for year
The more letters, the longer the result. "mmmm" gives January, "mmm" gives Jan, and "mm" gives 01.
Getting the month in full, from January to December (1/15/2024 gives “January”):
Getting the month followed by the year, from January 2024 to December 2025 (1/15/2024 gives “January 2024”):
Getting the day of the week, from Monday to Sunday (1/15/2024 gives “Monday”):
Getting the quarter in the form Q1, Q2, Q3 or Q4 (1/15/2024 gives “Q1”):
In a Power BI file set to English, you get:
Quarter Name = "Q" & QUARTER( Calendar[Date] )| Date | Month Name | Month and Year | Day | Quarter Name |
|---|---|---|---|---|
| 1/1/2024 | January | January 2024 | Monday | Q1 |
| 1/2/2024 | January | January 2024 | Tuesday | Q1 |
| 1/3/2024 | January | January 2024 | Wednesday | Q1 |
| 1/4/2024 | January | January 2024 | Thursday | Q1 |
| 1/5/2024 | January | Friday | ||
| 1/6/2024 | January | Saturday | ||
| 1/7/2024 | January | Sunday | ||
| 1/8/2024 | January | Monday | ||
| 1/9/2024 | January | Tuesday | ||
| 1/10/2024 | January | Wednesday | ||
| 1/11/2024 | January | Thursday | ||
| 1/12/2024 | January | Friday | ||
| 1/13/2024 | January | Saturday | ||
| 1/14/2024 | January | Sunday | ||
| 1/15/2024 | January | Monday | ||
| 1/16/2024 | January | Tuesday | ||
| 1/17/2024 | January | Wednesday | ||
| 1/18/2024 | January | Thursday | ||
| 1/19/2024 | January | Friday | ||
| 1/20/2024 | January | Saturday | ||
| 1/21/2024 | January | Sunday | ||
| 1/22/2024 | January | Monday | ||
| 1/23/2024 | January | Tuesday | ||
| 1/24/2024 | January | Wednesday |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
These columns are text. In a visual, Power BI therefore sorts them in alphabetical order, April before January. That is where the numbers come in. The Month column gives 1 for January, 2 for February, and so on. So sort the Month Name column by the Month column, with the Sort by column button of the Column tools tab. January then comes back to the top.
Placed on the rows of a “Table” visual, next to the “Revenue” measure, the “Year” column groups the sales by year:
| Year | Revenue |
|---|---|
| 2024 | 750,000 |
| 2025 | 950,000 |
| Total | 1,700,000 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
The 5 sales of 2024 come to 750,000, the 7 of 2025 to 950,000. In a slicer, the same “Year” column lets you filter the whole report on 2024 or on 2025.
Practice
Each exercise is solved with one of the functions shown here, on data other than the course data. Pick the right formula out of five.
Direct useCalculated columnDifficulty
A sports club records the sign-up date of each member in the “Members” table. Add to the “Members” table the calculated column “Year,” the year of sign-up.
Members Name Signup Inès 3/14/2024 Hugo 9/2/2025 Jade 1/20/2026 Which formula should you write for “Year”?
Direct useCalculated columnDifficulty
A bakery records the date of each order in the “Orders” table. Add to the “Orders” table the calculated column “Quarter,” the number of the quarter of the order.
Orders Order Date 1 2/14/2026 2 5/3/2026 3 11/21/2026 Direct useCalculated columnDifficulty
A weather station keeps its readings in the “Readings” table. Add to the “Readings” table the calculated column “Month,” the number of the month of each reading.
Readings Day Degrees 1/5/2026 -2 7/18/2026 31 12/30/2026 1 Direct useCalculated columnDifficulty
A carrier records the date of each delivery in the “Deliveries” table. For this carrier, the week starts on Monday. Add to the “Deliveries” table the calculated column “Week,” the number of the week of the delivery.
Deliveries Parcel Date C-201 1/2/2026 C-202 1/12/2026 C-203 3/15/2026 Direct useCalculated columnDifficulty
A hotel records the arrival date of each guest in the “Bookings” table. Add to the “Bookings” table the calculated column “Day,” the day of the week in full, like “Monday.”
Bookings Guest Arrival Alma 1/2/2026 Bruno 1/12/2026 Célia 3/15/2026
05.1.3A formula that needs a row
Let us go back to the “Year” column of Calendar:
Year = YEAR( Calendar[Date] )| Date | Year |
|---|---|
| 1/1/2024 | 2024 |
| 1/2/2024 | 2024 |
| 1/3/2024 | 2024 |
| 1/4/2024 | 2024 |
| 1/5/2024 | 2024 |
| 1/6/2024 | 2024 |
| 1/7/2024 | 2024 |
| 1/8/2024 | 2024 |
| 1/9/2024 | 2024 |
| 1/10/2024 | 2024 |
| 1/11/2024 | 2024 |
| 1/12/2024 | 2024 |
| 1/13/2024 | 2024 |
| 1/14/2024 | 2024 |
| 1/15/2024 | 2024 |
| 1/16/2024 | 2024 |
| 1/17/2024 | 2024 |
| 1/18/2024 | 2024 |
| 1/19/2024 | 2024 |
| 1/20/2024 | 2024 |
| 1/21/2024 | 2024 |
| 1/22/2024 | 2024 |
| 1/23/2024 | 2024 |
| 1/24/2024 | 2024 |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
The formula is calculated for each row of Calendar. On each row, Calendar[Date] refers to a single date, the one on that row, and YEAR draws the year from it.
Written as a measure, the same formula is rejected:
Power BI shows an error. A measure has no current row, except inside a function that goes through a table row by row, like SUMX, covered later. Calendar[Date] there refers to all 731 dates at once, and YEAR does not know which one to take. If a formula works as a column and not as a measure, this is very often the reason, and not a mistake on your part.
A physical table can get calculated columns too. In Customers, this column puts together the name and the city of each customer:
Customer and City = Customers[Name] & " (" & Customers[City] & ")"| Customer ID | Name | City | Customer and City |
|---|---|---|---|
| C001 | Orvane | New York | Orvane (New York) |
| C002 | Kumora | New York | Kumora (New York) |
| C003 | Talvio | New York | Talvio (New York) |
| C004 | Ribelia | Chicago | Ribelia (Chicago) |
| C005 | Movara | Chicago | Movara (Chicago) |
| C006 | Northel | Toronto | Northel (Toronto) |
| C007 | Sam Lee | Toronto | Sam Lee (Toronto) |
This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.
Written as a measure, it would be rejected for the same reason. Customers[Name] would refer to all 7 names at once.
In a calculated column, the formula always has a current row. A column name there gives the value on that row.
In a calculated column, you do not need to write the table name in front of a column of that same table:
Power BI understands that this is the Date column of Calendar, the table where you are adding the column. This formula returns the same result as YEAR( Calendar[Date] ).
In the same way, suppose Sales does not have its Amount column yet. Let us add it, for the amount of each sale:
On each row, Sales[Qty] gives the quantity of the sale, and Sales[Price] its price. The formula multiplies them.
Without the table name, you write:
Power BI understands that these are the Qty and Price columns of Sales, the table where you are adding the column. The result is the same.
Quiz
The questions often rely on the course tables. Keep them in view in their floating window, which you can move and enlarge.
Question 1
With the New measure button, you write Total Amount = Sales[Qty] * Sales[Price]. What happens?
Question 2
You add to Sales the calculated column Amount = [Qty] * [Price]. What does it hold on row V012, 5 cars at 10,000?
Question 3
Monday, January 1, 2024 opens week 1. What does Week = WEEKNUM( Calendar[Date], 2 ) return on the row of Sunday, 1/14/2024?
- A calculated column can be added with the New column button, to a physical table as well as to a calculated table.
- In a calculated column, a column written on its own gives the value of the row. Written in a measure, it is rejected, except inside a function that goes through a table row by row, like SUMX, covered later.