Create Calendar Table in One Click using TMDL View in Power BI

Create Calendar Table in One Click using TMDL View in Power BI


Creating a robust, reusable Calendar Table is one of the most essential steps in any data modeling process. And now with the introduction of TMDL (Tabular Model Definition Language) in Power BI, this process becomes not just easier but faster than ever—literally in one click.

In this blog, I’ll show you how you can use the TMDL View in Power BI to instantly create a rich calendar table with fiscal year handling, week numbers, month names, and more. You can also check out the step-by-step walkthrough video I’ve created for better visual understanding ๐Ÿ“น.


๐Ÿš€ What is TMDL View in Power BI?

TMDL (Tabular Model Definition Language) is a new declarative way to define tabular models in Power BI using code—making your model components (tables, columns, measures, partitions) more manageable, auditable, and reusable.


With TMDL support enabled, you can now:

  • View and edit model metadata in human-readable format

  • Create model objects directly using code (like calculated tables, measures, etc.)

  • Track and version model changes easily using source control


๐Ÿง  Why Use a Calendar Table?

Having a dedicated Calendar Table enables:

  • Proper time intelligence (e.g., YTD, MTD, QTD calculations)

  • Consistent filtering and grouping across visuals

  • Fiscal year handling

  • Easier customizations for weeks, months, quarters


⚙️ How to Create Calendar Table using TMDL View?

Here’s a sample TMDL definition for a Calendar Table you can plug into the TMDL view.

๐Ÿงพ TMDL Code:

createOrReplace table Calendar lineageTag: 3984c24d-ea4e-4741-8685-c8c1b917b9cc column Date formatString: General Date lineageTag: a1dbc3cf-c187-4c92-910c-8d706785fd4e summarizeBy: none sourceColumn: [Date] column Year formatString: 0 sourceColumn: [Year] column YearNumber formatString: 0 sourceColumn: [YearNumber] column QuarterOfYear formatString: 0 sourceColumn: [QuarterOfYear] column MonthOfYear formatString: 0 sourceColumn: [MonthOfYear] column DayOfMonth formatString: 0 sourceColumn: [DayOfMonth] column DateInt formatString: 0 sourceColumn: [DateInt] column MonthName sourceColumn: [MonthName] column MonthInCalendar sourceColumn: [MonthInCalendar] column QuarterInCalendar sourceColumn: [QuarterInCalendar] column DayInWeek formatString: 0 sourceColumn: [DayInWeek] column DayOfWeekName sourceColumn: [DayOfWeekName] column WeekNumber formatString: 0 sourceColumn: [Week Number] column MonthnYear formatString: 0 sourceColumn: [MonthnYear] column QuarternYear formatString: 0 sourceColumn: [QuarternYear] column ShortYear sourceColumn: [ShortYear] column FY sourceColumn: [FY] partition Calendar = calculated mode: import source = ``` VAR StartDate = DATE(2025,1,1) VAR EndDate = DATE(2025,12,31) VAR FYStartMonth = 4 VAR Dates = CALENDAR(StartDate, EndDate) RETURN ADDCOLUMNS( Dates, "Year", FORMAT([Date], "yyyy"), "YearNumber", YEAR([Date]), "QuarterOfYear", QUARTER([Date]), "MonthOfYear", MONTH([Date]), "DayOfMonth", DAY([Date]), "DateInt", YEAR([Date]) * 10000 + MONTH([Date]) * 100 + DAY([Date]), "MonthName", FORMAT([Date], "MMMM"), "MonthInCalendar", FORMAT([Date], "MMM") & " " & FORMAT([Date], "yyyy"), "QuarterInCalendar", "Q" & QUARTER([Date]) & " " & FORMAT([Date], "yyyy"), "DayInWeek", WEEKDAY([Date], 1) - 1, "DayOfWeekName", FORMAT([Date], "dddd"), "Week Number", WEEKNUM([Date], 2), "MonthnYear", YEAR([Date]) * 10000 + MONTH([Date]) * 100, "QuarternYear", YEAR([Date]) * 10000 + QUARTER([Date]) * 100, "ShortYear", RIGHT(YEAR([Date]), 2), "FY", "FY" & IF(MONTH([Date]) >= FYStartMonth, RIGHT(YEAR([Date]) + 1, 2), RIGHT(YEAR([Date]), 2)) ) ```

๐Ÿ”ง Steps to Implement:

  1. ✅ Enable TMDL View in Power BI Desktop (Preview feature)

  2. ✅ Navigate to TMDL View in Power BI Desktop and Create a New Script.

  3. ✅ Paste the above code into the TMDL Script Interface (Refer below screenshot)

  4. ✅ Click on Apply button on top left.

  5. ✅ Calendar table will get created, click on the refresh now button.


  6. Explore the calendar table from the Data view


  7. Note: If you want to change the date range or FY Start month then you can change it in the variables created in line 72,73 & 74. (Screenshot attached)

๐ŸŽฅ Step-by-Step Video Guide

I've also created a detailed video tutorial showing each step from enabling TMDL to using the Calendar table in your reports.

๐Ÿ‘‰ Watch now on my YouTube channel [ANMOLPOWERBICORNER]
๐Ÿ”— Video Link: https://youtu.be/ogEcYqf1yJI


๐Ÿ“Œ Final Thoughts

TMDL is a game-changer for Power BI developers. With just one snippet of code, you now have a full-featured, reusable Calendar Table ready to go! This will help you:

  • Save time ⏳

  • Maintain consistency across reports ๐Ÿ“Š

  • Simplify versioning and collaboration using Git ✅


๐Ÿ’ฌ Have questions or want to connect? Feel free to reach out to me on Anmol Malviya.

๐Ÿ“ Follow my blog series for more such Power BI TMDL tips and tricks!

Comments

Popular posts from this blog

Embedding Power BI Reports in Websites and Applications: A Complete Guide

Import Microsoft Planner Data into Power BI Using Power Automate and SharePoint

Difference between Append and Merge in Power BI