cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ALeef Member
Member

Possible Tip/Trick: Dynamic Date Dimension Table

I'm going to share the dynamic date dimension table I built, hopefully it is useful to someone!  I named it DateTable for this tutorial, and my fact table FactTable.

 

The table is built using the following formula:

DateTable = CALENDAR (MINX('FactTable', [Created Date]), NOW())

Basically, it looks for the oldest date you have for the column [created date], and builds a sequential date range until the time of refresh - so it always has calendar information for all data points in the set.

 

I added the following columns:

Date = This is built when you create the table

Year = YEAR([Date])

MonthofYear = MONTH([Date])

QuarterofYear = ROUNDUP (MONTH([Date])/3,0)

OrdinalDate = DATEDIFF([Year]&",1,1",[Date],DAY)+1

DayofWeek = WEEKDAY([Date],2)

ISOWeekofYear = IF ((([OrdinalDate] - [DayofWeek] + 10)/7) >= 53, 1, TRUNC(([OrdinalDate] - [DayofWeek] + 10)/7))

DayofMonth = DAY([Date])

 

Month = FORMAT([Date], "MMM") & " " & [Year])

Quarter = "Q" & [Quarter] & " " & [Year]

Week Ending = [Date] + (7- [DayofWeek])

Day = Format([Date],"DDDD")

 

 

With both the numeric and text values, you can use "Sort by" to properly order them in visuals.  If you want your week numbers to start on a Sunday instead of Monday, change the "1" to a "2" in ISOWeekofYear column - however ISO Standard is a Monday Start.

 

I'm still pretty new to PowerBI, but I'll help if I can!  If you have suggestions or modifications, I'd love to hear them.

 

EDIT:  I changed how the week number is calculated, so I can use ISO Week Numbers.  This also helped fix the "week Ending column, which broke when spanning multiple years that included a leap year.  Let me know if you find any problems!

 

EDIT2:  MS just released the timeline slicer for PowerBI.  That probably, mostly makes this table useless.  Read more here: http://blogs.msdn.com/b/powerbi/archive/2015/11/03/visual-awesomeness-unlocked-the-timeline-slicer.a...

 

39 REPLIES 39
RJ Regular Visitor
Regular Visitor

Re: Possible Tip/Trick: Dynamic Date Dimension Table

Hi

 

Thanks for this

 

What would you do if you wanted more than one calendar. Say an Invoice Date plus an Order Date Calendar

 

Would you need two new tables or could one be set up (called  DateTable) and filter by date type in the measure somehow?

 

Is this possible

 

Thanks

 

EDIT. To do the above

 

http://community.powerbi.com/t5/Desktop/Linking-2-or-more-dates-to-one-Master-Calendar-USERELATIONSH...

 

 

konstantinos Senior Member
Senior Member

Re: Possible Tip/Trick: Dynamic Date Dimension Table

@ALeef Great Job..Only needs a SWITCH for the month names and set...

@RJ You can create a second Calendar or use the same with inactive relantionship & USERELANTIONSHIP.

Konstantinos Ioannou
ALeef Member
Member

Re: Possible Tip/Trick: Dynamic Date Dimension Table

@konstantinos : Why would you use a switch and type in all the names, rather than use the format function?  Is it a perfromance difference?

 

@RJ :  Check out http://community.powerbi.com/t5/Desktop/Transitive-Relationships/m-p/8563#U8563 .  It's an interesting concept, and apparently having inactive relationships is fine - the software is still smart enough to filter right through.  It wasn't exactly what I ended up using, but that's because I wasn't using a slicer, I wanted a clustered column chart.

konstantinos Senior Member
Senior Member

Re: Possible Tip/Trick: Dynamic Date Dimension Table

@ALeef Apologies..SWITCH is slower of course. To be honest I wasn't aware that FORMAT can return months and days due to always importing Date Table..

Thanks, always learning..

Konstantinos Ioannou
RJ Regular Visitor
Regular Visitor

Re: Possible Tip/Trick: Dynamic Date Dimension Table

BTW I always use today() not now()

 

Does it make any difference?

ALeef Member
Member

Re: Possible Tip/Trick: Dynamic Date Dimension Table

TODAY() only returns a day, and sets the time to 12:00am.  For this instance, I don't think it matters, but I use timestamps regularly, so that is what I'm in the habit of.

 

Good question!

bernitorres Visitor
Visitor

Re: Possible Tip/Trick: Dynamic Date Dimension Table

I am new to PowerBI and I don't understand how to actually create this table.

I tried creating a New Source -> Blank Query and inserting your query, but that doesn't seem to work.

 

Could you please add some more detailed steps on how to add it to the queries, for newbies like me? Smiley Happy

konstantinos Senior Member
Senior Member

Re: Possible Tip/Trick: Dynamic Date Dimension Table

@bernitorres You can create/import tables with 2 ways. One is importing with "Get Data" and the other is through DAX data modelling.

You need to go to the data model view and in the ribbon go to modeling tab & select "New Table". thus using DAX language.

The "Get data" uses M language which is used only for importing data to data model.

 

Keep in mind that you need to already have import some data in order to see the :Modelling" tab..

1.png

Konstantinos Ioannou
ALeef Member
Member

Re: Possible Tip/Trick: Dynamic Date Dimension Table

@konstantinos has it right.  I made it using the New Table option on the ribbon.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 53 members 1,165 guests
Please welcome our newest community members: