Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

How to compare two columns and return data from a third column?

Hi Community,   Example data set in Power Query Hours Project Catagory Production Catagory Internal (formula) External (formula) 3 Men's Men's 3 null 5 Women's Women's 5 nul...
  • v-yalanwu-msft's avatar
    3 years ago

    Hi, Anonymous ;

    You could add conditional column as follow:

    Then add another conditional column.

    The final show:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlbSUfJNzYspNTAwMi9G5cTqRCuZAoXC83ORVaBwQWrMgILemSkIFUgckLwRuh1uibmZOZVgORMEF8NuQ0J2xwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hours = _t, #"Project Catagory" = _t, #"Production Catagory" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hours", Int64.Type}, {"Project Catagory", type text}, {"Production Catagory", type text}}),
        #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Internal", each if [Project Catagory] = [Production Catagory] then [Hours] else null),
        #"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "External", each if [Project Catagory] <> [Production Catagory] then [Hours] else null)
    in
        #"Added Conditional Column1"


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.