Building an Effective Date Table with DimDate for KPI Measurement and Chart Decluttering in Power BI

This article discusses the Date Dimension (DimDate) Table and explains how to employ it for KPI measurement using time intelligence functions.

Iwa Sanjaya
Microsoft Power BI
7 min readFeb 23, 2024

--

Cover Image by Author

What is Date Dimension (DimDate)?

Preview of dimDate Table in Power BI

In Power BI, the Date Dimension (DimDate) table is like a calendar that helps organize and understand your data based on dates. It breaks down dates into different parts like year, month, day, etc., making it easier to analyze and visualize your data over time. This table is really useful for creating reports and doing calculations that involve dates, such as comparing sales between different months or years.

How to Establish DimDate Table

a. Create New Table

To create DimDate table in Power BI, go to Table view, create new table, and input the following formula:

Here’s an explanation of each part of the code:

  • DimDate =: This line names the table that will be created as "DimDate".
  • ADDCOLUMNS ( ... ): This function is used to add columns to the table.
  • CALENDAR ("2000-01-01", "2019-12-31"): This function generates a list of dates starting from January 1, 2000, to December 31, 2019. It creates a continuous sequence of dates within this range.
  • "DateInt", FORMAT ( [Date], "YYYYMMDD" ): This creates a new column named "DateInt" that formats the date in the format YYYYMMDD. This format is useful for sorting dates numerically.
  • "Year", YEAR ( [Date] ): This creates a new column named "Year" that extracts the year from the date.
  • "Monthnumber", FORMAT ( [Date], "MM" ): This creates a new column named "Monthnumber" that extracts the month number from the date.
  • "MonthNameShort", FORMAT ( [Date], "mmm" ): This creates a new column named "MonthNameShort" that displays the abbreviated month name.
  • "MonthNameLong", FORMAT ( [Date], "mmmm" ): This creates a new column named "MonthNameLong" that displays the full month name.
  • "DayOfWeekNumber", WEEKDAY ( [Date] ): This creates a new column named "DayOfWeekNumber" that assigns a number to each day of the week (e.g., Sunday = 1, Monday = 2, etc.).
  • "DayOfWeek", FORMAT ( [Date], "dddd" ): This creates a new column named "DayOfWeek" that displays the full day of the week name.
  • "DayOfWeekShort", FORMAT ( [Date], "ddd" ): This creates a new column named "DayOfWeekShort" that displays the abbreviated day of the week name.
  • "Quarter", "Q" & FORMAT ( [Date], "Q" ): This creates a new column named "Quarter" that displays the quarter of the year in the format "Q1", "Q2", etc.
  • "YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" ): This creates a new column named "YearQuarter" that displays the year followed by the quarter in the format "YYYY/Q1", "YYYY/Q2", etc.

I’m giving you the code below for easy copying and pasting. Feel free to modify the date range in your formula to match your dataset.

DimDate = 
ADDCOLUMNS (
CALENDAR ("2022-01-01", "2023-09-30"),
"DateInt", FORMAT ( [Date], "YYYYMMDD" ),
"Year", YEAR ( [Date] ),
"Monthnumber", FORMAT ( [Date], "MM" ),
"MonthNameShort", FORMAT ( [Date], "mmm" ),
"MonthNameLong", FORMAT ( [Date], "mmmm" ),
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfWeek", FORMAT ( [Date], "dddd" ),
"DayOfWeekShort", FORMAT ( [Date], "ddd" ),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "YYYY" ) & "/Q" & FORMAT ( [Date], "Q" ),
"EndOfMonth", EOMONTH([Date], 0)
)

b. Mark as Date Table

Mark your dimDate table as date table

After you’ve established your DimDate table, don’t forget to ‘Mark as date table’.

Connect the DimDate Table with Date Column Within Other Table

Connecting dimDate table with main table in Model view

Make sure you have the date column(s) on your main table, otherwise the ‘DimDate’ table won’t have any function. In the Model view, connect the ‘Date’ column with the date column in your other table. In my case, since I’m dealing with multiple tables, I establish a connection between the ‘DimDate’ table and the transaction dates within the ‘Sales’ table.

How to Put It Into Use? — Utilizing Time Intelligence Functions

DimDate offers a multitude of capabilities, especially in time-related contexts, which can be achieved through the application of time intelligence functions.

Time intelligence functions are tools used in software like Microsoft Power BI and SQL Server Analysis Services (SSAS). They help analyze and compare data over different time periods. With these functions, you can study trends, compare performance over time, and do other time-related analyses. For instance, you can calculate year-to-date totals (TOTALYTD), compare with the same period in the previous year (SAMEPERIODLASTYEAR), or add or subtract time intervals from dates (DATEADD). These functions are essential for creating dynamic reports and dashboards that show how metrics change over time.

a. Same Period Last Year

Arguably one of the most commonly used time intelligence functions, SAMEPERIODLASTYEAR allows us to compare data from the same period of time in the previous year. So, if you’re looking at sales for January 2023, SAMEPERIODLASTYEAR will show you the sales for January 2022. It’s like having a “time machine” to see how things were going at the same time last year.

To utilize this function, we need to create a measurement and apply SAMEPERIODLASTYEAR in the filter section, specifying the date parameter for comparison. By default, we typically use the date column from our time dimension.

Total Revenue SAMEPERIODLASTYEAR = 
CALCULATE(([Total Revenue]), SAMEPERIODLASTYEAR(DimDate[Date]))

Using this metric, we can create a Key Performance Indicator (KPI) representing the percentage improvement compared to the previous year. In this case, it involves dividing the variance between the “Total Revenue” for the selected period and the “Total Revenue” for the equivalent period in the previous year by the “Total Revenue” for the same period in the previous year.

If the revenue for the current year exceeds that of the previous year, it will be displayed in green; otherwise, it will be displayed in red.

% Total Revenue SAMEPERIODLASTYEAR = 
(([Total Revenue] - [Total Revenue SAMEPERIODLASTYEAR]) / [Total Revenue SAMEPERIODLASTYEAR]) - 1
KPI for % Change from Same Period PY (in January)

b. Total Year-to-Date (YTD), Quarter-to-Date (QTD), Month-to-Date (MTD)

i. Year-to-Date

This function examines the expression across the entire year, beginning on the first day and ending on the last date, after applying the specified filter.

Total YTD
Total Revenue TOTALYTD = 
TOTALYTD(([Total Revenue]), DimDate[Date])

ii. Quarter-to-Date

This function begins its assessment from the first day of the quarter and extends until the last date, evaluating the expression with the specified filter applied.

Total QTD
Total Revenue TOTALQTD = 
TOTALQTD(([Total Revenue]), DimDate[Date])

iii. Month-to-Date

Similar to previous functions, this one evaluates the expression over a timeframe starting from the beginning of the month and ending at the last date, with specified filters applied.

Total Revenue TOTALMTD = 
TOTALMTD(([Total Revenue]), DimDate[Date])

c. Previous Day, Previous Month, Previous Quarter, and Previous Year

Total Revenue PREVIOUSDAY = 
CALCULATE(([Total Revenue]), PREVIOUSDAY(DimDate[Date]))

Total Revenue PREVIOUSMONTH =
CALCULATE(([Total Revenue]), PREVIOUSMONTH(DimDate[Date]))

Total Revenue PREVIOUSQUARTER =
CALCULATE(([Total Revenue]), PREVIOUSQUARTER(DimDate[Date]))

Total Revenue PREVIOUSYEAR =
CALCULATE(([Total Revenue]), PREVIOUSYEAR(DimDate[Date]))

BONUS: you can further enhance the visual appeal and improve audience understanding of your chart.

Suppose you aim to display sales trends for a given period. Using your typical ‘date’ table might result in a cluttered chart that makes it difficult to discern the trend. By employing DimDate, you can streamline the chart, focusing solely on end-of-month data. This simplification not only declutters the chart but also makes it much easier to interpret the sales trend.

Cluttered Chart vs. Decluttered Chart

Conclusion

Employing the DimDate table allows you to craft visually appealing and interactive dashboards, ensuring that charts are easily understood by readers, and effectively conveying key information to stakeholders through KPI measurements.

Don’t forget to subscribe to

👉 Power BI Publication

👉 Power BI Newsletter

and join our Power BI community

👉 Power BI Masterclass

--

--

Iwa Sanjaya
Microsoft Power BI

A data storyteller, making complex data approachable for non-data savvy.