Forum Discussion

Plump_Lil_Monk's avatar
Plump_Lil_Monk
Frequent Visitor
2 years ago
Solved

Custom Column: Conditional Value Return

Hi, I have a problem that I am trying to figure out. I need to create a custom column that enters a value based on a high-low condition in another column.   I have a year column with 2024 and 20...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Plump_Lil_Monk ,

    Please try this M code:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlGK1UFlmGIwsErFAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
      let 
        currentYear = Date.Year(DateTime.LocalNow()),
        AddedCustom = if [Year] = currentYear then "Current" else "Current + " & Text.From([Year] - currentYear)
      in 
        AddedCustom)
    in
        #"Added Custom"

    Put all of it into the advanced editor, and the final output is below:



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