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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
TechR21
Helper V
Helper V

Conditional column based on date column

Hi,

 

I have following column with dates + times in it:

TechR21_0-1674642484794.png

I want to create an extra column which gives me just the date of this start time column, with the following logic: If the date/time in start time column < 16:00 then it should give the date - 1 day, else the date mentioned.

 

So for example with above data

Start time                        Date (new column)

15/01/2023 18:00:00           15/01/2023

15/01/2023 02:30:00           14/01/2023

 

2 REPLIES 2
johnt75
Super User
Super User

You could add a custom column in Power Query something like

if Time.Hour([StartTime]) < 16 then Date.AddDays([StartTime], -1) else [StartTime]
Syndicate_Admin
Administrator
Administrator

You can create a new column using the "DATE" function and an "IF" statement to achieve this.

The "DATE" function takes a date/time value as an input and returns only the date part. The "IF" statement can be used to check if the start time is less than 4:00 PM, and if so, subtract one day from the date.

Here is the formula you can use to create the new column:

= IF(TIME(HOUR([Start time]), MINUTE([Start time]), SECOND([Start time])) < TIME(16,0,0), DATE([Start time])-1, DATE([Start time]))

You can use this formula in the "New column" option of the "Modeling" tab, in the "Add Column" section.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.