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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ruslan_Baranov
New Member

Change date by time

Hello all.

 

I have two columns "Date" and "Time". I need to add a third column with the date "New Date".
The date should change not at 00:00 but at 06:00.

 

Example:
Weighing date March 1, 2023, time 11:39, "New date" March 1, 2023
Weighing date March 2, 2023, time 04:56, "New date" March 1, 2023

 

Date.PNG

 

Thank you in advance for your cooperation.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Ruslan_Baranov 

you may try

New Date =
DATEVALUE (
'Table'[2nd Weight Date] + 'Table'[2nd Weight Time]
- TIME ( 6, 0, 0 )
)

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Ruslan_Baranov 

you may try

New Date =
DATEVALUE (
'Table'[2nd Weight Date] + 'Table'[2nd Weight Time]
- TIME ( 6, 0, 0 )
)

Thanks a lot for help, now it's working.

andrewpirie
Resolver II
Resolver II

I believe I understand this as for any times before 6am, the new date column should show the previous date, for times of 6am or later it should show the 2nd Weight date. Because this is a static property of the 2nd weight, and the 6am changeover time doesn't change, I suggest doing this in PowerQuery. 

 

Here's an expression to do this with a custom column in PowerQuery:

if Time.Hour([2nd Weight Time]) >= 6 then [2nd Weight Date] else Date.AddDays([2nd Weight Date], -1)

 

Here's the equivalent in DAX for a calculated column, but this would be less performant, so try the above first:

 

New Date =
IF(
    HOUR([2nd Weight Time]) < 6,
    'Weight Date and Times'[2nd Weight Date] - 1,
    'Weight Date and Times'[2nd Weight Date]
)

Thanks a lot, but I tried this way and it's not workig.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors