In this blog, we will perform different Date and Time Function in PowerBI. Then we can get the required and importance of following functions:
Introduction
Date and time functions in PowerBI enable advanced manipulation and analysis of date-time data. Functions like DATE
, TODAY
, NOW
, YEAR
, MONTH
, DATEDIFF
, and FORMAT
allow users to create dynamic calculations, filter data by periods, and generate insights such as trends, durations, and time-based aggregations in reports.
Dataset Description
This user dataset includes unique user IDs, usernames, emails, dates of birth, and account creation timestamps, allowing for user analysis by demographics, registration dates, and identification details.
The link to download the dataset is here.
Steps to perform different Date and Time Function in PowerBI:
Step 1. Open Power BI Desktop
Step 2. Click on Get Data to select Text/CSV in Home tab
Step 3. Browse csv file and hit Open
Step 4. A window will open to Transform Data and Load, click on Transform Data
Now, let’s dive into date/time functions:
Date.From:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.From`and following formula:
= Date.From([created_at])
Date.Year:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.Year` and following formula:
= Date.Year([created_at])
Date.Month:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.Month` and following formula:
= Date.Month([created_at])
Date.Day:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.Day` and following formula:
= Date.Day([created_at])
Date.DayOfWeek:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.DayOfWeek` and following formula:
= Date.DayOfWeek([created_at])
Date.DayOfYear:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.DayOfYear` and following formula:
= Date.DayOfYear([created_at])
Date.QuarterOfYear:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.QuarterOfYear` and following formula:
= Date.QuarterOfYear([created_at])
Date.StartOfYear:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.StartOfYear` and following formula:
= Date.StartOfYear([created_at])
Date.EndOfYear:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.EndOfYear` and following formula:
= Date.EndOfYear([created_at])
Date.StartOfMonth:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.StartOfMonth` and following formula:
= Date.StartOfMonth([created_at])
Date.EndOfMonth:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.EndOfMonth` and following formula:
= Date.EndOfMonth([created_at])
Date.StartOfWeek:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.StartOfWeek` and following formula:
= Date.StartOfWeek([created_at])
Date.EndOfWeek:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.EndOfWeek` and following formula:
= Date.EndOfWeek([created_at])
Date.AddYears:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.AddYears` and following formula:
= Date.AddYears([created_at], 1)
Date.AddMonths:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.AddMonths` and following formula:
= Date.AddMonths([created_at], 1)
Date.AddDays:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Date.AddDays` and following formula:
= Date.AddDays([created_at], 10)
Time.From:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Time.From` and following formula:
= Time.From([created_at])
Time.Hour:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Time.Hour` and following formula:
= Time.Hour([created_at])
Time.Minute:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Time.Minute` and following formula:
= Time.Minute([created_at])
Time.Second:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Time.Second` and following formula:
= Time.Second([created_at])
Time.StartOfHour:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Time.StartOfHour` and following formula:
= Time.StartOfHour([created_at])
Time.EndOfHour:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Time.EndOfHour` and following formula:
= Time.EndOfHour([created_at])
DateTime.From:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.From` and following formula:
= DateTime.From([created_at])
DateTime.LocalNow:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.LocalNow` and following formula:
= DateTime.LocalNow()
DateTimeZone.UtcNow:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTimeZone.UtcNow` and following formula:
= DateTimeZone.UtcNow()
DateTime.Date:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.Date` and following formula:
= DateTime.Date([created_at])
DateTime.Time:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.Time` and following formula:
= DateTime.Time([created_at])
DateTime.ToText:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.ToText` and following formula:
= DateTime.ToText([created_at], “yyyy-MM-dd HH:mm:ss”)
DateTime.FromText:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.FromText` and following formula:
= DateTime.FromText([DateTime.ToText])
DateTime.ToRecord:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `DateTime.ToRecord` and following formula:
= DateTime.ToRecord([created_at])
Duration.From:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Duration.From` and following formula:
= Duration.From(DateTime.LocalNow() – [created_at])
Duration.Days:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Duration.Days` and following formula:
= Duration.Days(DateTime.LocalNow() – [created_at])
Duration.Hours:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Duration.Hours` and following formula:
= Duration.Hours(DateTime.LocalNow() – [created_at])
Duration.Minutes:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Duration.Minutes` and following formula:
= Duration.Minutes(DateTime.LocalNow() – [created_at])
Duration.Seconds:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Duration.Seconds` and following formula:
= Duration.Seconds(DateTime.LocalNow() – [created_at])
Duration.ToText:
Step 1. Go to Add Column tab and select Custom Column
Step 2. Type column name `Duration.ToText` and following formula:
= Duration.ToText(DateTime.LocalNow() – [created_at])
Now the Final Step after performing above all functions:
Step Final: Go to Home tab and hit Close & Apply
Conclusion
Date and Time function plays important role in data analytics when we need to track event or find pattern on time.
In this documentation, we studied that how Date and Time function used and what it does. There are lots of function in Date, Time, DateTime, DateTimeZone, Duration in Power BI.
If you like this blog, you can share it with your friends or colleague. You can connect with me on social media profiles like LinkedIn, Twitter, and Instagram. If you have any doubt feel free to comment.
- 👏 Like for this article and subscribe to our newsletter
- 📰 View more content on my DataSpoof website
- 🔔 Follow Me: LinkedIn| Youtube | Instagram | Twitter