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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
maqboolk51
New Member

Calculate if delivered time in between the range of Slot Date and Slot time in Power BI

Hi I'm new to Power BI and I have a question if any one can help.

 

I basically want to know if my order was delivered in between the Date and Slot time provided by the customer. 

 

IdOrder Created Date TimeDelivered Date TimeSlot DateSlot Time
194306901/09/2023 02:3401/09/2023 15:1001/09/202309:00 - 12:00
194307001/09/2023 02:3901/09/2023 20:0001/09/202318:00 - 21:00
194307101/09/2023 02:4201/09/2023 16:5001/09/202315:00 - 18:00
194307301/09/2023 02:4801/09/2023 11:0601/09/202309:00 - 12:00
194307401/09/2023 02:5104/09/2023 13:4404/09/202312:00 - 15:00
194307501/09/2023 02:5304/09/2023 13:4304/09/202312:00 - 15:00
194307801/09/2023 03:0001/09/2023 20:3901/09/202318:00 - 21:00
194307901/09/2023 03:0302/09/2023 13:4602/09/202315:00 - 18:00
194308001/09/2023 03:0501/09/2023 13:5701/09/202315:00 - 18:00
194308201/09/2023 03:0901/09/2023 13:5101/09/202312:00 - 15:00
3 REPLIES 3
ThxAlot
Super User
Super User

Very straightforward, #date & #time produces #datetime

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJbCsQgDAXQrYjfHZqnVbdSuv9tjHaEIQkz9Ks00NMbr+eZsQlDaXnLgDu0nYA4AXUWO0LtCGY0X1oHSK+ENJ752hZ3QOTcHwjmF47D+uEILYeBE3LpStfI6UpXLceRq44bAcrTZSVwegeWL8ddxIxmOlqcWk4jx5Hjp5zbDNif+6zCtfOnCn9RBndHIZOumNHvKqq/KINz+w9Oj4fNVopcixwGzp7d9QY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, #"Order Created Date Time" = _t, #"Delivered Date Time" = _t, #"Slot Date" = _t, #"Slot Time" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Id", Int64.Type}, {"Order Created Date Time", type datetime}, {"Delivered Date Time", type datetime}, {"Slot Date", type date}, {"Slot Time", type text}}),
    Check = Table.AddColumn(#"Changed Type", "Check", each let span = List.Transform(Text.Split([Slot Time], " - "), Time.From) in [Slot Date] & span{0} <= [Delivered Date Time] and [Delivered Date Time] <= [Slot Date] & span{1})
in
    Check

ThxAlot_0-1698859113807.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



slorin
Super User
Super User

Hi

another solution

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJbCsQgDAXQrYjfHZqnVbdSuv9tjHaEIQkz9Ks00NMbr+eZsQlDaXnLgDu0nYA4AXUWO0LtCGY0X1oHSK+ENJ752hZ3QOTcHwjmF47D+uEILYeBE3LpStfI6UpXLceRq44bAcrTZSVwegeWL8ddxIxmOlqcWk4jx5Hjp5zbDNif+6zCtfOnCn9RBndHIZOumNHvKqq/KINz+w9Oj4fNVopcixwGzp7d9QY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, #"Order Created Date Time" = _t, #"Delivered Date Time" = _t, #"Slot Date" = _t, #"Slot Time" = _t]),
ChType = Table.TransformColumnTypes(Source,{{"Order Created Date Time", type datetime}, {"Delivered Date Time", type datetime}, {"Slot Date", type datetime}}),
AddOnTime = Table.AddColumn(ChType, "AddOnTime", each
[Delivered Date Time] >= [Slot Date] + Duration.From(Text.Start([Slot Time],5))
and
[Delivered Date Time] <= [Slot Date] + Duration.From(Text.End([Slot Time],5)),
type logical)
in
AddOnTime

with "Slot Date" = type datetime and not type date

 

Stéphane

m_dekorte
Super User
Super User

Hi @maqboolk51 

 

Give this a go

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdJbCsQgDAXQrYjfHZqnVbdSuv9tjHaEIQkz9Ks00NMbr+eZsQlDaXnLgDu0nYA4AXUWO0LtCGY0X1oHSK+ENJ752hZ3QOTcHwjmF47D+uEILYeBE3LpStfI6UpXLceRq44bAcrTZSVwegeWL8ddxIxmOlqcWk4jx5Hjp5zbDNif+6zCtfOnCn9RBndHIZOumNHvKqq/KINz+w9Oj4fNVopcixwGzp7d9QY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, #"Order Created Date Time" = _t, #"Delivered Date Time" = _t, #"Slot Date" = _t, #"Slot Time" = _t]),
    ChType = Table.TransformColumnTypes(Source,{{"Order Created Date Time", type datetime}, {"Delivered Date Time", type datetime}, {"Slot Date", type date}}),
    AddOnTime = Table.AddColumn(ChType, "OnTime", each 
        ( Date.From([Delivered Date Time]) = [Slot Date] ) and 
        [   t= Time.From([Delivered Date Time]), 
            s= List.Transform( Text.Split([Slot Time], " - "), Time.From ), 
            r= s{0} <= t and s{1} >= t
        ][r], type logical
    )
in
    AddOnTime

 

returns this result

m_dekorte_0-1698848882894.png

 

I hope this is helpful

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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
Top Kudoed Authors