Forum Discussion

Tand81's avatar
Tand81
Regular Visitor
6 years ago
Solved

Grouped fill down by Dates

Hello.  I have an issue in Power query.  First colomn contains order information and second colomns contains Dates(first apperance is Date on stock and second is delivery to customer). How can I fi...
  • v-alq-msft's avatar
    6 years ago

    Hi, Tand81 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may go to 'Query Editor' and input the following codes in 'Advanced Editor'.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc7BCQAhDETRXnJW1ESdWIvYfxvu6i6I6C3M40NqJQFQ1MKTIXXi2PN7BmpmR/xoP9WYNVhNz5Qdx61dFNcWQxnndqr4S6zjrVDO8VROa9w6", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ORdPos = _t, Date = _t, Cont = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ORdPos", type text}, {"Date", type date}, {"Cont", Int64.Type}}),
        Custom2 = Table.AddColumn(#"Changed Type","RE",each 
    let x=[ORdPos],y=[Date]
    in 
    Duration.Days( Table.Max(Table.SelectRows(#"Changed Type",each [ORdPos]=x),"Date")[Date]-y)
    ),
        Custom3 = Table.AddColumn(Custom2,"list",each let x=[RE] in List.Generate(()=>1,each _<=x,each _+1)),
        #"Expanded list" = Table.ExpandListColumn(Custom3, "list"),
        Custom4 = Table.AddColumn(#"Expanded list","NewDate",each if
    [list]<>null then [Date]+#duration([list]-1,0,0,0) else [Date]),
        #"Removed Columns" = Table.RemoveColumns(Custom4,{"Date", "RE", "list"})
    in
        #"Removed Columns"

     

    Result:

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.