Forum Discussion

seppel123's avatar
seppel123
Frequent Visitor
2 years ago
Solved

Power Query: Lookup a value in a give timeframe and return in custom column

Hi everyone,   i have a problem with a dataset that i tried to solve with a custom column in Power Query. My data shows how long a Container ("Container", Nr. of container) is in the Depot ("Depot...
  • lbendlin's avatar
    lbendlin
    2 years ago

    I'll give you the general direction.  But I can't really judge how useful that would be to do in Power Query.  I'd rather do it in DAX or not at all.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZJNDoIwEEbvwnps5gfa6QGMBzCuCDcg7ry/FQUHaBGNs6B8kL686bRtq9PxfFFUCXqIFVSE6XG99f1qEXSojpFlHjpYQbL7FZT8UGFJS28Yi7R/KhEC0yQxp2EzWaTgt5SyNq+FLWb4lgG8f25uNyEHaUoQUkc4QkzY20oAr3XgRy1p7HfQCNT7wjGnngyt2aIxlQTTeIjMrMawt0GBKEqxTrWkJZ/PNIKg8qy1m1o3/dqthhiQRFWHM4iWVjvi326lxZRu5XQ4XJyeoOGY0HV3", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Container = _t, #"Filling 1" = _t, #"Filling 2" = _t, #"Filling 3" = _t, Depot = _t, Start = _t, End = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Filling 1 end", each if [Depot] = "null" then null else
    try Table.SelectRows(Source,(k)=> [Container]=k[Container] and [Start]=k[Start] and k[Filling 1]<> "null")[End]{0} otherwise null)
    in
        #"Added Custom"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.