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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
JoshuaIdumijie
Regular Visitor

Approximate Date & Time Based on Condition

ArrivalTimeDesired Results
1/30/2023 5:001/30/2023 8:00
1/24/2023 15:001/24/2023 15:00
1/27/2023 17:301/30/2023 8:00

 

Please, I need to create a column that achieves the result above. When the arrival time is before 8 AM on a weekday then the column should contain 8 AM same day but if the arrival time is later than 4 PM then it should contain 8 AM the next week day. But if the arrival time is on a weekend then it should contain 8 AM the next weekday. 

Weekend is Saturday and Sunday and Weekdays are Monday to Friday. 

 

1 REPLY 1
FreemanZ
Super User
Super User

hi @JoshuaIdumijie 

 

you data table and description is not consistent. I tried following your description:

Result = 
VAR _date = FORMAT([ArrivalTime], "m/d/yyyy")
VAR _time = FORMAT([ArrivalTime], "h:mm")
VAR _time8 = TIME(8, 0, 0)
VAR _weekday = WEEKDAY(_date, 2)
VAR _nextweekday =
MINX(
    FILTER(
        CALENDAR( MIN(TableName[ArrivalTime]), MAX(TableName[ArrivalTime])),
        [Date]>VALUE(_date) && NOT WEEKDAY([Date], 2) IN {6, 7}
    ),
    [Date]
)
RETURN
IF(
    NOT _weekday IN {6,7} && VALUE(_time)<= _time8,  
    _date&" "&_time8, 
    _nextweekday&" "&_time8
)

 

it worked like this:

FreemanZ_1-1675148337948.png

 

you may verify that with more data. 

 

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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