As time travelling is yet to be invented, the dimension of time tends to be rather crucial in most reporting scenarios. I can only imagine the implications time travels will have on the BI business! “As you can see the trend is going upwards! This is great!” “Yesterday I showed you how the trend is going upwards but due to time travelers altering the history, the trend is now going downwards”
“The service desk reporting shows that we take an average of 10 hours to handle Password resets. This is unacceptable! I suggest 2 agents shall travel back in time and reset the password for the 10 cases with the longest handling time at the very same time as the password reset was requested, thus greatly reducing our average handling time”
“What was the result of last years bookings? 7% margin?! Oh no! What was our lowest month in terms of revenue? Let’s discuss how we can try that month again for a better outcome, shall we”
Anyhow, let’s not dwell on the future and instead focus on the present, where the time dimension is often needed in Power BI reporting. If you find your self in need, feel free to copy this sample to get your calendar and/or time tables for your reports 🙂
When you need dates and some meta data for said date, this is your go to place! Sure, there’s a hierarki built for you by default for year, quarter, Month and day but sometimes you want to make relations to other tables and they only have for example the year. In any case, it’s quicker to delete something than to create it so use this as a starting point.
The first 11 rows of the DAX Table is looks like this. You have 2 options. Set a manual start and end date for your table (or use formulas) or simply use the CalendarAuto-function. Both will work and both will create the entire table with all the meta data for you.
After this row, the table is created for you like this. Note that I’ve set the return type of Week No and Week day to 2 at row 35 and 36. This means that we want new weeks to begin on Mondays. Feel free to change this if your have other preferences.
Remender to set week day name to be sorted on week day No after creation, this way you will get the week days in the correct order instead of alphabetically.
The full query can be copied here:
// If you wish to set manual dates, do it here. You can also use formulas to select for example the minimal value of a column in the report
VAR StartDate = "2021-01-01"
VAR EndDate = "2021-12-31"
// Uncomment the option you wish below. Comment out the other option
// Calendar will use the start and end date above
// CalendarAuto will automatically find the earliest and latest date in the model
VAR CalendarTable =
"Week Day No",WEEKDAY([Date],2),
"Week Day Name",
WEEKDAY([Date],2) > 5,
Time of Day
The second table is the Time of Day. I’ve made 2 tables for you to choose from here. The first one will only create 1 column and it’s customizable to your preferences. If you for example know that you’ll be needing 10 minutes increments from 08:00 to 18:00, the table will not create any other unnecessary rows for you.
You set the starttime, the end time and finally the increments on row 5, 6 and 7.
This creates the table like so:
By changing the variables at the top you can get a completely different table:
This table is useful if you don want any extra columns that you wont be using anyway. You know what you want and just want that. Simple! The code can be found here:
Time of Day =
// Set the variables for the Time Series like this:
// StartTime and EndTime should the in the format HH:MM like 08:15 or 17:50
// The increments is the amount of minutes for each row, like 1, 2, 3 or 5, 10, 15.
VAR StartTime = "08:07"
VAR EndTime = "23:40"
VAR Increments = 10
// No need to change anything below this line
VAR StartValue =
((LEFT(StartTime,2) * 60)
VAR EndValue =
((LEFT(EndTime,2) * 60)
VAR IncrementValue = (1/24/60)*Increments
Time of Day (Full)
This table gives you a row for every minute of the day from midnight to midnight! It then, just like the calendar, gives you more data per row to play with. This table could also be a substitute for the Group function where Power BI can bin a value. If you only need to group 1 column it might be faster to do it that way, if you want to bin multiple time columns from different tables it’s probably faster to simply relate them to this time table instead.
This is a sample of how the 30 minutes increments looks like. Remember that you can stack these columns so that the user can actually decide on the granularity in the report themselves!
By using the left arrows, the user can step down in the hierarki and decide if they want to see the data in 30 minutes intervalls down to 5 minutes intervalls. Well actually if you simply include the Time-column you can drill down to just 1 minute intervalls too!
Speaking of 1 minute intervalls, sometimes you want that without the hour dimension. Using this column you can look into differences of how trends appear during any hour of the day. I would for example bet that you express a certain behavior for meetings that can be tracked like this. At 45 minutes, you probably usually look at your phone to determine what next meeting is about to start and what you were about to prepare. In the offices I would bet that the amount of coffee cups produced by coffee machines have a great increase between 45-57 minutes as well as between minute 15-27. Using this vital insight you could plan your coffee gathering to low activity times of the hour, saving what I can only assume to be multiple seconds on a yearly basis. Seconds you just wasted reading a weird hypothesis on effective coffee collecting time of the hour. My bad.
Should this table be desirable in your Power BI arsenal, I present you with the DAX code below: