Forum Discussion

marktvc's avatar
marktvc
Helper I
5 years ago
Solved

Add an "Active Record" column

Hi All, I have a Table - RatePlan and 2 specifc Columns I'm focusing on:   UNIQLIN (Id from another table) INSERTDATE (date)   The field UNIQLIN appears multiple times but with different dates ...
  • Jimmy801's avatar
    5 years ago

    Hello marktvc 

     

    you can add a Group-function on your ID with 2 function. AllRows and MaxDate of your date-column.

    After that expand your grouped table and check whether your date-column is the same as the MaxDate.

    Here some code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIw1TMw0jMyUIrVgQgYG+gZGCMLGBnoGcJVOAEFDC3QBYAqDMACsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UNIQLIN = _t, INSERTDATE = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"UNIQLIN", type text}, {"INSERTDATE", type date}}, "de-DE"),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"UNIQLIN"}, {{"MaxDate", each List.Max([INSERTDATE]), type date}, {"AllRows", each _, type table [UNIQLIN=text, INSERTDATE=date]}}),
        #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"INSERTDATE"}, {"INSERTDATE"}),
        #"Added Custom" = Table.AddColumn(#"Expanded AllRows", "CURRENT_RECORD", each if [MaxDate]=[INSERTDATE] then "Y" else "N"),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"MaxDate"})
    in
        #"Removed Columns"

    transforms this

     

    into this

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy