Power BI Exercise - Creating a Date Table and Month-to-Date Sales (Retail Dataset)
Power BI Exercise - Creating a Date Table and Month-to-Date Sales (Retail Dataset)
Build a reliable calendar model and track cumulative monthly sales.
In this guided exercise, you will create a proper Date table, connect it to the retail Sales table, and calculate month-to-date sales. You will also build a daily sales trend and validate the cumulative results in DAX Query View.
Why create a Date table?
The Sales[SaleDate] column records when each transaction occurred. It is suitable for storing transaction dates, but a dedicated Date table provides one continuous row for every calendar date and reusable fields such as Year, Month, and Day.
A good Date table should have:
- One row for every date in the selected period
- A unique Date column with no blank values
- No missing dates
- A relationship to the transaction table
- Useful calendar attributes for report grouping and filtering
Before you begin
Open the retail Power BI file and confirm that:
- The transaction table is named
Sales. Sales[SaleDate]has the Date data type.- The measure
[Total Sales]exists. - The unfiltered Total Sales value is 21,788.
Step 1: Create the Date table
- Select the Table tools or Modeling ribbon.
- Select New table.
- Enter the following DAX expression and press Enter.
Date =
VAR FirstYear = YEAR ( MIN ( Sales[SaleDate] ) )
VAR LastYear = YEAR ( MAX ( Sales[SaleDate] ) )
RETURN
ADDCOLUMNS (
CALENDAR (
DATE ( FirstYear, 1, 1 ),
DATE ( LastYear, 12, 31 )
),
"Year", YEAR ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Month Name", FORMAT ( [Date], "MMMM" ),
"Year Month", FORMAT ( [Date], "YYYY-MM" ),
"Day", DAY ( [Date] ),
"Day Name", FORMAT ( [Date], "dddd" )
)
For the current dataset, this creates one row for every day from 1 January 2026 through 31 December 2026.
Step 2: Mark it as a Date table
- Select the new Date table.
- On the Table tools ribbon, select Mark as date table.
- Select the
Date[Date]column. - Select OK.
This identifies the unique, continuous date column Power BI should use for classic time-intelligence calculations.
Step 3: Sort Month Name correctly
- Select
Date[Month Name]. - On the Column tools ribbon, select Sort by column.
- Select
Date[Month Number].
This prevents month names from appearing alphabetically.
Step 4: Create the relationship
- Open Model view.
- Drag
Date[Date]ontoSales[SaleDate]. - Confirm the cardinality is One to many (1:*).
- Confirm the cross-filter direction is Single.
- Confirm the relationship is active, and select OK.
| Relationship side | Column | Role |
|---|---|---|
| One side | Date[Date] | One unique row per date |
| Many side | Sales[SaleDate] | Multiple sales can occur on a date |
Step 5: Create the Month-to-Date measure
- Select the Sales table.
- Select New measure.
- Enter the following formula.
Sales MTD =
TOTALMTD (
[Total Sales],
'Date'[Date]
)
TOTALMTD evaluates Total Sales from the start of the current month through the current date in the filter context.
Step 6: Build a daily sales table
- Open Report view.
- Add a Table visual.
- Add
Date[Date],[Total Sales], and[Sales MTD]. - In the visual filter pane, set
[Total Sales]to is not blank. - Sort the table by Date in ascending order.
| Date | Daily Total Sales | Sales MTD |
|---|---|---|
| 3 Jan 2026 | 2,599 | 2,599 |
| 4 Jan 2026 | 267 | 2,866 |
| 6 Jan 2026 | 1,598 | 4,464 |
| 8 Jan 2026 | 718 | 5,182 |
| 10 Jan 2026 | 796 | 5,978 |
| 12 Jan 2026 | 2,099 | 8,077 |
| 14 Jan 2026 | 999 | 9,076 |
| 17 Jan 2026 | 3,598 | 12,674 |
| 20 Jan 2026 | 695 | 13,369 |
| 22 Jan 2026 | 1,467 | 14,836 |
| 24 Jan 2026 | 916 | 15,752 |
| 26 Jan 2026 | 1,499 | 17,251 |
| 28 Jan 2026 | 2,398 | 19,649 |
| 29 Jan 2026 | 1,587 | 21,236 |
| 31 Jan 2026 | 552 | 21,788 |
Step 7: Validate the result in DAX Query View
- Open DAX Query View.
- Enter the following query.
- Select Run.
EVALUATE
FILTER (
SUMMARIZECOLUMNS (
'Date'[Date],
"Daily Sales", [Total Sales],
"Sales MTD", [Sales MTD]
),
NOT ISBLANK ( [Daily Sales] )
)
ORDER BY 'Date'[Date]
The query should return 15 transaction dates. The final row, 31 January 2026, should show Sales MTD of 21,788.
Step 8: Create the sales trend chart
- Add a Line chart to the report canvas.
- Place
Date[Date]on the X-axis. - Place
[Total Sales]and[Sales MTD]on the Y-axis. - Set the X-axis type to Continuous.
- Give the chart the title Daily Sales and Month-to-Date Sales.
Step 9: Test the Date table
- Add a slicer using
Date[Date]. - Change the slicer style to Between.
- Select 1 January through 17 January 2026.
- Confirm Total Sales is 12,674.
- Extend the end date to 31 January and confirm Total Sales returns to 21,788.
The slicer filters the Date table. The active relationship then propagates the matching dates to the Sales table.
Knowledge check
- Why should a Date table contain dates with no sales transactions?
- Why is Date placed on the one side of the relationship?
- What is the difference between daily Total Sales and Sales MTD?
- Why should Month Name be sorted by Month Number?
- How does the Date slicer filter the Sales table?
Troubleshooting
| Problem | What to check |
|---|---|
| Sales MTD equals daily sales on every row. | Verify the Date table is connected to Sales and that the visual uses Date[Date], not Sales[SaleDate]. |
| Sales MTD is blank. | Confirm the relationship is active and both relationship columns use the Date data type. |
| The chart shows every day of 2026. | Apply a visual filter for Total Sales is not blank, or restrict the displayed date range. |
| Months appear alphabetically. | Sort Month Name by Month Number. |
| The final total is not 21,788. | Clear other slicers and verify that all 15 retail records are loaded. |
Exercise complete
- The Date table covers the complete 2026 calendar year.
- The Date table is marked using
Date[Date]. - A one-to-many active relationship connects Date to Sales.
- Sales MTD reaches 21,788 on 31 January.
- The table, query, slicer, and line chart produce the expected results.