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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
vinayk
Regular Visitor

Power BI Custom Date and Time Query

I have a Date measure that calculates the total line production in a day and they range from 12 midnight to 11.59pm. Now I need to calculate the same between 6am to 5.59 am next day. I have the below power query already written for Date column

 

Date=
ADDCOLUMNS(
CALENDAR (DATE (2015,1,1), DATE (2025, 12, 31) ),
"DateKey", FORMAT ( [Date], "YYYYMMDD"),
"YearKey", YEAR ( [Date] ),
"Monthnumber", FORMAT ( [Date], "MM" ),
"YearMonthnumber", FORMAT ( [Date],"MvMM"),
"YearMonthShort", FORMAT ( [Date], "mmm M" ),
"MonthNameShort", FORMAT ( [Date],
"MonthNameLong", FORMAT ( [Date],
"DayOfWeekNumber", WEEKDAY ( [Date] ),
"DayOfweek", FORMAT ( [Date],"dddd" )
"DayOfheekShort", FORMAT ( [Datel," ddd"),
"Quarter", "Q" & FORMAT ( [Date], "Q" ),
"YearQuarter", FORMAT ( [Date], "M" ) & "/Q" & FORMAT ( [Date], "Q" )
 )

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@vinayk , No need to change the date calendar. Change the date in fact 

 

New column =

var _time = timevalue([Datetime])

var _date = datevalue([Datetime])

return

if(_time<time(6,0,0) , _date -1, _date)

 

Join this new date date column with date table

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@vinayk , No need to change the date calendar. Change the date in fact 

 

New column =

var _time = timevalue([Datetime])

var _date = datevalue([Datetime])

return

if(_time<time(6,0,0) , _date -1, _date)

 

Join this new date date column with date table

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks a lot @amitchandak

It worked 🙂

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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