Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Joerobert
Advocate V
Advocate V

Help with Date table

Hello,

 

I don't really know the importance of date tables so I thought i would attempt to create one and apply to my data model as a trial run. Unfortunately i cannot get it properly set up. After obtaining various examples via google, i was able to create the following code in Power Query however I am noticing the following behavior:

1. The date column does not appear to generate for the entire year, as specified in the parameter

2. I am noticing some strange behavior with the data when attempting to sort

3. I am seeing a strange row count when i scroll down to the bottom of the table

 

My current data currently contains multiple tables that has multiple date/time columns where time is included with the date. As aresult, I am attempting to incorporate time in the date table so that I can relate the two tables for time intelligence functions.

 

//Create Date Dimension
(StartDate as datetime, EndDate as datetime)=>

let
//Capture the date range from the parameters
    StartDate = #datetime(Date.Year(StartDate), Date.Month(StartDate), 
    Date.Day(StartDate),1,1,0),
    EndDate = #datetime(Date.Year(EndDate), Date.Month(EndDate), 
    Date.Day(EndDate),1,1,0),

//Get the number of dates that will be required for the table
    GetDateCount = Duration.TotalMinutes(EndDate - StartDate),

//Take the count of dates and turn it into a list of dates
    GetDateList = List.DateTimes(StartDate, GetDateCount, 
    #duration(0,0,1,0)),

//Convert the list into a table
    DateListToTable = Table.FromList(GetDateList, 
    Splitter.SplitByNothing(), {"Date"}, null, ExtraValues.Error),

//Create various date attributes from the date column
//Add Year Column
    YearNumber = Table.AddColumn(DateListToTable, "Year", 
    each Date.Year([Date])),

//Add Quarter Column
    QuarterName = Table.AddColumn(YearNumber , "Quarter Name", 
    each "Q" & Number.ToText(Date.QuarterOfYear([Date]))),

//Add Quarter Column2
    QuarterNo = Table.AddColumn(QuarterName , "Quarter No", 
    each Date.QuarterOfYear([Date])),

//Add Week Number Column
    WeekNumber= Table.AddColumn(QuarterNo , "Week of Year", 
    each Date.WeekOfYear([Date])),

//Add Month Number Column
    MonthNumber = Table.AddColumn(WeekNumber, "Month Number", 
    each Date.Month([Date])),

//Add Month Name Column
    MonthName = Table.AddColumn(MonthNumber , "Month Name", 
    each DateTime.ToText([Date],"MMMM")),

//Add Day of Year Column
    Day = Table.AddColumn(MonthName, "Day", 
    each Date.Day([Date])),

//Add Day of Year Column
    DayOfYear = Table.AddColumn(Day, "Day of Year", 
    each Date.DayOfYear([Date])),

//Add Day of Week Column
    DayOfWeek = Table.AddColumn(DayOfYear , "Day of Week", 
    each DateTime.ToText([Date],"dddd"))
in
    DayOfWeek

 

2018-04-15_13-32-27.jpg

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Joerobert,

You can create a normal calendar table as Greg_Deckler's post, and create a date type field using dax in your fact table, then create one-to-many relationship between calendar table and fact table.

Do you get any issues using the above method?

Regards,
Lydia

View solution in original post

6 REPLIES 6
Greg_Deckler
Community Champion
Community Champion

I put in 1/1/2017 and 12/31/2017 as my parameters. Seems like it stopped at 12/31/2017 @ 1:00 AM.

 

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

That is a lot of work to create a calendar/date table when DAX has CALENDAR and CALENDARAUTO and a ton of other nice date functions like WEEKNUM, WEEKDAY, etc. Do you really need every minute of every day? I'll give your code a shot and see what I come up with though.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I was just playing with it again after posting and I was able to utilize in a report with only dates. I have date and time in my fact tables so I just thought I need to replicate it for the relationship.

You bring up a good point about the DAX functions, I guess I should just build up the basic table.

I am looking at this again, using a date table while carrying date/time in my fact table and I am only seeing a relationship with the rows where the timestamp ends in 12:00:00 AM. It does look like I might need to carry a timestamp in my date table and therefore carrying a duration for every minute.

Anonymous
Not applicable

@Joerobert,

You can create a normal calendar table as Greg_Deckler's post, and create a date type field using dax in your fact table, then create one-to-many relationship between calendar table and fact table.

Do you get any issues using the above method?

Regards,
Lydia

Thanks Lydia, i acutally performed this very same task to get my issues resolved; just coverted the original column in my fact table to date type and I am now able to bring in all the rows through the relationship.

 

Thanks for your help!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.