Forum Discussion

franorio's avatar
franorio
Helper III
9 years ago
Solved

New Status Conditional/Calculated Column/ Measure or how would you do it?

Hello everybody, need your help cracking this out. Working with a movement adherence report, got two tables   Table 1 dataset columns are: Employee ID, Full Name, Last Calification (values can be ...
  • MarcelBeug's avatar
    9 years ago

    In Power Query you can unpivot the Policy table and replace N/Y with Not OK and OK:

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Policy"]}[Content],
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ACTION"}, "Calification", "Status"),
        #"Y/N to OK/Not OK" = Table.TransformColumns(#"Unpivoted Other Columns",{{"Status", each if _ = "N" then "Not OK" else "OK"}})
    in
        #"Y/N to OK/Not OK"

     

    Now you can merge Table 2 with both Table1 and the Policy table:

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", Int64.Type}, {"Type of movement", type text}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Employee ID"},Table1,{"Employee ID"},"NewColumn",JoinKind.LeftOuter),
        #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Last Calification"}, {"Last Calification"}),
        #"Merged Queries1" = Table.NestedJoin(#"Expanded NewColumn",{"Type of movement", "Last Calification"},Policy,{"ACTION", "Calification"},"NewColumn",JoinKind.LeftOuter),
        #"Expanded NewColumn1" = Table.ExpandTableColumn(#"Merged Queries1", "NewColumn", {"Status"}, {"Status"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded NewColumn1",{"Last Calification"})
    in
        #"Removed Columns"