Forum Discussion

Mohan1005's avatar
Mohan1005
Regular Visitor
7 years ago
Solved

Row duplication and updation

Hi,   I need help in power query to achieve the following scenario. if we are comparing current month id's with previous months id's and if some id's are not present in the current month and presen...
  • Zubair_Muhammad's avatar
    7 years ago

    Mohan1005 

     

    Please try this one

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlHSUTIyMLQEUoZKsTooAkZgAVN0FUgCxmABM4SACbqAqVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Month = _t, Year = _t, ID = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Year", Int64.Type}, {"ID", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let myIDs=Table.SelectRows(#"Changed Type",(x)=>(x)[Month]<=[Month] 
    and (x)[Year]<=[Year])[ID]
    in {List.Min(myIDs)..List.Max(myIDs)}),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"ID"}),
        #"Removed Duplicates" = Table.Distinct(#"Removed Columns", {"Month", "Year"}),
        #"Expanded Custom" = Table.ExpandListColumn(#"Removed Duplicates", "Custom")
    in
        #"Expanded Custom"