Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How to conditionally update fields in one column, based upon data in another column.

I'm trying to find a way thru query to update a date field in one column, based upon the conditional value of another column.  Is there a way to do this?   Here is a simple example. Record Cre...
  • CNENFRNL's avatar
    5 years ago

    Anonymous , Table.ReplaceValue, as well as Table.ReplaceText, is one of the most powerful function in M language which one could imagine; it does the trick for your request with ease. You might want to try

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcxBDoAwCATAv3BuQsFS9ajVVxD+/w0B0952d5JVhQsKNCTkytUj8dYErCjcP8iUgJ4yvHWfpwTsKY83QVoScKS8+Y287kJOMPsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Record = _t, #"Created Date" = _t, #"Work ID" = _t]),
    
        Custom1 = Table.ReplaceValue(Source, "", each if [Work ID]="23456" then Source{[#"Work ID"="56789"]}[Created Date] else [Created Date], (x,y,z)=>z, {"Created Date"})
    in
        Custom1