Forum Discussion

Jorge_Dacsa's avatar
Jorge_Dacsa
New Member
3 years ago
Solved

Fullfill Time Serie data column

Hi, I have a doubt, maybe someone has the solution....

 

I have a time serie data column without weekends. I want to fullfill the time serie creating automatically the registers I need.  The rest of fields, my idea is, once I have the new register, leave those columns in blank (null) and fill down with the value before. But i do not know how to automatice this.

 

 

  • Hi Jorge_Dacsa 

     

    Here is my solution. First create a blank query and paste below code into its Advanced Editor. Please modify FirstDate and LastDate values according to the table you have. 

    let
        FirstDate = #date(2004,12,13),
        LastDate = #date(2005,1,4),
        Source = List.Dates(FirstDate, Duration.Days(LastDate - FirstDate) + 1, #duration(1,0,0,0)),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}})
    in
        #"Renamed Columns"

    Then you will have a table that has all dates between the start date and end date you have set.  

     

    In the original table, click Merge Queries. Select Fecha in the first table. Select "All Dates" as the second table and select Date column. Expand Join Kind box and select Right Outer. Click OK. 

    You will see a All Dates column added to the original table. There is a new null row which contains all weekend dates that are missing in the original table. 

     

    Then expand All Dates column. Sort the newly added Date column ascendingly. Remove the old Fecha column. Fill down other columns except Date column. Reorder columns. 

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc+7DcAgFEPRXahR4Jn/LIj910gUiOP2yMX1nM4QLAXEmJ13dpm55bdmUVCLaKJW0UxtouVTRNFKNdFGhWinau+gSi9zIQngNXTRfztEeS1JLngtSS7OtfBmlW3nWMhiz611Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Fecha = _t, Value = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Fecha", type date}, {"Value", type number}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Fecha"}, #"All Dates", {"Date"}, "All Dates", JoinKind.RightOuter),
        #"Expanded All Dates" = Table.ExpandTableColumn(#"Merged Queries", "All Dates", {"Date"}, {"Date"}),
        #"Sorted Rows" = Table.Sort(#"Expanded All Dates",{{"Date", Order.Ascending}}),
        #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Fecha"}),
        #"Filled Down" = Table.FillDown(#"Removed Columns",{"Value"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Filled Down",{"Date", "Value"})
    in
        #"Reordered Columns"

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

2 Replies

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi Jorge_Dacsa 

     

    Here is my solution. First create a blank query and paste below code into its Advanced Editor. Please modify FirstDate and LastDate values according to the table you have. 

    let
        FirstDate = #date(2004,12,13),
        LastDate = #date(2005,1,4),
        Source = List.Dates(FirstDate, Duration.Days(LastDate - FirstDate) + 1, #duration(1,0,0,0)),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}})
    in
        #"Renamed Columns"

    Then you will have a table that has all dates between the start date and end date you have set.  

     

    In the original table, click Merge Queries. Select Fecha in the first table. Select "All Dates" as the second table and select Date column. Expand Join Kind box and select Right Outer. Click OK. 

    You will see a All Dates column added to the original table. There is a new null row which contains all weekend dates that are missing in the original table. 

     

    Then expand All Dates column. Sort the newly added Date column ascendingly. Remove the old Fecha column. Fill down other columns except Date column. Reorder columns. 

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc+7DcAgFEPRXahR4Jn/LIj910gUiOP2yMX1nM4QLAXEmJ13dpm55bdmUVCLaKJW0UxtouVTRNFKNdFGhWinau+gSi9zIQngNXTRfztEeS1JLngtSS7OtfBmlW3nWMhiz611Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Fecha = _t, Value = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Fecha", type date}, {"Value", type number}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Fecha"}, #"All Dates", {"Date"}, "All Dates", JoinKind.RightOuter),
        #"Expanded All Dates" = Table.ExpandTableColumn(#"Merged Queries", "All Dates", {"Date"}, {"Date"}),
        #"Sorted Rows" = Table.Sort(#"Expanded All Dates",{{"Date", Order.Ascending}}),
        #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Fecha"}),
        #"Filled Down" = Table.FillDown(#"Removed Columns",{"Value"}),
        #"Reordered Columns" = Table.ReorderColumns(#"Filled Down",{"Date", "Value"})
    in
        #"Reordered Columns"

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Community Champion

    =let a=Table.Buffer(PreviousStepName) in Table.FromRecords(List.Transform(List.Dates(List.Min(a[Fecha]),Duration.Days(List.Max(a[Fecha])-List.Min(a[Fecha]))-1,Duration.From(1)),each a{[Fecha=_]}? ??[Fecha=_]),null,2)