Search code examples
excelpowerbipowerquerypowerbi-desktopm

PowerQuery Custom Function: column value in set of numbers


I am brand new to PowerQuery. I want to make a custom column with a value of 1 if the column value is in a set of numbers (e.g., 3,6,9,14) and 0 otherwise. Besides a big if statement for all the values I'm searching, is there any easier way?


Solution

  • enter image description here

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if List.Contains({3,6,9,14}, [Column1]) then 1 else 0)
    in
        #"Added Custom"