Cloud Wars
  • Home
  • Top 10
  • CW Minute
  • CW Podcast
  • Categories
    • AI and Copilots
    • Innovation & Leadership
    • Cybersecurity
    • Data
  • Member Resources
    • Cloud Wars AI Agent
    • Digital Summits
    • Guidebooks
    • Reports
  • About Us
    • Our Story
    • Tech Analysts
    • Marketing Services
  • Summit NA
  • Dynamics Communities
  • Ask Copilot
Twitter Instagram
  • Summit NA
  • Dynamics Communities
  • AI Copilot Summit NA
  • Ask Cloud Wars
Twitter LinkedIn
Cloud Wars
  • Home
  • Top 10
  • CW Minute
  • CW Podcast
  • Categories
    • AI and CopilotsWelcome to the Acceleration Economy AI Index, a weekly segment where we cover the most important recent news in AI innovation, funding, and solutions in under 10 minutes. Our goal is to get you up to speed – the same speed AI innovation is taking place nowadays – and prepare you for that upcoming customer call, board meeting, or conversation with your colleague.
    • Innovation & Leadership
    • CybersecurityThe practice of defending computers, servers, mobile devices, electronic systems, networks, and data from malicious attacks.
    • Data
  • Member Resources
    • Cloud Wars AI Agent
    • Digital Summits
    • Guidebooks
    • Reports
  • About Us
    • Our Story
    • Tech Analysts
    • Marketing Services
    • Login / Register
Cloud Wars
    • Login / Register
Home » The Importance of a ‘Calendar’ or ‘Date’ Table with samples in M and Dax
News

The Importance of a ‘Calendar’ or ‘Date’ Table with samples in M and Dax

Ashley HsiaBy Ashley HsiaJanuary 16, 2021Updated:June 18, 20213 Mins Read
Facebook Twitter LinkedIn Email
Share
Facebook Twitter LinkedIn Email

To turn off Time intelligence – here is a great blog resource: sqlbi – DAX 101: Automatic time intelligence in Power BI

You want your date table to encompass all of the dates you will be using (so if you have a lost of historic data, you will need your calendar to cover the earliest dates you are utilizing). 

Guy in a Cube has a great video to get started with a DAX calendar. Here is some DAX based on that:

Dates =

VAR BaseCalendar =

CALENDARAUTO (6)

RETURN

GENERATE (

BaseCalendar,

VAR BaseDate = [Date]

VAR YearDate = YEAR ( BaseDate)

VAR MonthNumber = MONTH ( BaseDate)

RETURN ROW (

“Day”, BaseDate,

“Year”, YearDate,

“Month Number”, MonthNumber,

“Month”, FORMAT ( BaseDate, “mmmm”),

“Year Month”, FORMAT (BaseDate, “mmm yy”),

“Quarter”, “Q”&FORMAT (BaseDate, “q”)

)

)

If you would like something a little more manual and spelled out, this is a good resource: ArcherPoint – Creating A Date Table In Power BI

If you want to get started with a Calendar Table in Power Query (M), here are two samples you can test out:

1. This one looks at the dates in a Sales table that has opportunities listed out in the future:

let

  StartDate = List.Min(Table.Column(Sales,”ContractDate”)),

  EndDate = List.Max(Table.Column(Sales,”ContractDate”)),

  DayCount = Duration.Days(Duration.From(EndDate – StartDate)),

  Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),

  TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),

  ChangedType = Table.TransformColumnTypes(TableFromList,{{“Column1”, type date}}),

  RenamedColumns = Table.RenameColumns(ChangedType,{{“Column1″,”Date”}}),

  AddYear = Table.AddColumn(RenamedColumns, “Year”, each Date.Year([Date]), type number),

  AddQuarter = Table.AddColumn(AddYear, “Quarter”, each Date.QuarterOfYear([Date]), type number),

  AddCY = Table.AddColumn(AddQuarter, “CY”, each if Date.IsInCurrentYear([Date]) then 1 else 0),

  AddCQ = Table.AddColumn(AddCY, “CQ”, each if Date.IsInCurrentQuarter([Date]) then 1 else 0),

  ThreeYearsPrior = Table.AddColumn(AddCQ,”3 Year Lookback”, each if Date.IsInPreviousNYears([Date],3) then 1 else 0),

  AddPY = Table.AddColumn(ThreeYearsPrior,”PY”, each if Date.IsInPreviousYear([Date]) then 1 else 0),

  AddMonthNumber = Table.AddColumn(AddPY,”Month”, each Date.Month([Date]), type number),

  AddMonthName = Table.AddColumn(AddMonthNumber,”Month Name”, each Date.MonthName([Date]), type text),

  #”Changed Type” = Table.TransformColumnTypes(AddMonthName,{{“PY”, Int64.Type}, {“3 Year Lookback”, Int64.Type}, {“CQ”, Int64.Type}, {“CY”, Int64.Type}})

  

in

  #”Changed Type”

2. This one is based on data that has only populated out to the current day and we want the Calendar table to go to the end of the current calendar year:

let

  StartDate = List.Min(Table.Column(Finance,”Month”)),

  EndDate = Date.EndOfYear(List.Max(Table.Column(Finance,”Month”))),

  DayCount = Duration.Days(Duration.From(EndDate – StartDate)),

  Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),

  TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),

  ChangedType = Table.TransformColumnTypes(TableFromList,{{“Column1”, type date}}),

  RenamedColumns = Table.RenameColumns(ChangedType,{{“Column1″,”Date”}}),

  AddYear = Table.AddColumn(RenamedColumns, “Year”, each Date.Year([Date]), type number),

  AddQuarter = Table.AddColumn(AddYear, “Quarter”, each Date.QuarterOfYear([Date]), type number),

  AddMonth = Table.AddColumn(AddQuarter, “Month”, each Date.Month([Date]), type number),

  AddMonthName = Table.AddColumn(AddMonth,”Month Name”, each Date.MonthName([Date]), type text),

  AddCY = Table.AddColumn(AddMonthName, “CY”, each if Date.IsInCurrentYear([Date]) then 1 else 0),

  AddCQ = Table.AddColumn(AddCY, “CQ”, each if Date.IsInCurrentQuarter([Date]) then 1 else 0)

in

  AddCQ

Here are some resources I used to eventually build my tables:

https://community.powerbi.com/t5/Desktop/Date-Dimension-Table-that-Dynamically-Pulls-Start-and-End-dates/td-p/76870

INSIGHTS & OUTLIERS – Need a Good Date Table for Power BI?

POWER BI TIPS AND TRICKS – Building Date Table from Scratch 

If you have some awesome tip, please share them in the comments.

Power Platform
Share. Facebook Twitter LinkedIn Email
Ashley Hsia

High performing individual with aptitude for quick learning and creative yet analytical problem solving. History of leadership roles, public speaking, and business process improvement. Spring 2019 winner of IS-6489’s Kaggle Housing prediction competition.

Related Posts

AI Agent & Copilot Podcast: Victor Dantas of Eyedeas on Power Platform, Digital Innovation

March 14, 2025

AI Agent & Copilot Podcast: Mary Myers on Tapping Into AI Models Within Power Platform

March 7, 2025

AI Agent & Copilot Podcast: Senthamil Selvan of Acumant on Using AI With Power Platform, Microsoft’s Ecosystem

March 3, 2025

Larry Ellison Sees ‘Unimaginable’ AI Opportunity as Oracle Q2 RPO Jumps 50% to $97 Billion

December 10, 2024
Add A Comment

Comments are closed.

Recent Posts
  • Microsoft Adopts A2A Protocol, Agentic AI Era Begins
  • AI Agent & Copilot Podcast: Finastra Chief AI Officer Lays Out Range of Use Cases, Microsoft Collaboration
  • IBM Launches Microsoft Practice to Accelerate AI, Cloud, and Security Transformation
  • AI Agent & Copilot Podcast: JP Morgan Chase CISO Publicly Pushes for Stronger Security Controls
  • ServiceNow Re-Invents CRM for End-to-End Enterprise

  • Ask Cloud Wars AI Agent
  • Tech Guidebooks
  • Industry Reports
  • Newsletters

Join Today

Most Popular Guidebooks

Accelerating GenAI Impact: From POC to Production Success

November 1, 2024

ExFlow from SignUp Software: Streamlining Dynamics 365 Finance & Operations and Business Central with AP Automation

September 10, 2024

Delivering on the Promise of Multicloud | How to Realize Multicloud’s Full Potential While Addressing Challenges

July 19, 2024

Zero Trust Network Access | A CISO Guidebook

February 1, 2024

Advertisement
Cloud Wars
Twitter LinkedIn
  • Home
  • About Us
  • Privacy Policy
  • Get In Touch
  • Marketing Services
  • Do not sell my information
© 2025 Cloud Wars.

Type above and press Enter to search. Press Esc to cancel.

  • Login
Forgot Password?
Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.