Forum Discussion

George1973's avatar
George1973
Helper V
3 years ago
Solved

Pivot Column NonAgregate Error

Hi All, I have a following table: Where I want to pivot the column "Start_End" with the "Leave_Date" column values for every "ID".. Like given below for instance (ID = 82):    When ...
  • George1973's avatar
    George1973
    3 years ago

    Dear v-jingzhang ,

     

    I have finally solved the issue, thanks to your main recommendations.
    - Index Column added
    - Added calculated column: Index column devided by 2
    - Calculated column has been splitted extracting the whole number (before " . " delimiter)
    - As a result I've got grouped index column where star/end operations are groupped
    - First index column has been deleted
    - Pivot Start / End Column with values in "Leave_dates" with "No Agregation" (Please note that "no Groupping" action was required)
    - Some unnnessesary columns were also deleted

    As a final result I've got the desired table:

    Here is the ultimate M code:

     #"Added Index" = Table.AddIndexColumn(#"Removed Columns", "Index", 0, 1, Int64.Type),
        #"Added Custom" = Table.AddColumn(#"Added Index", "Index_Group", each [Index]/2),
        #"Split Column by Delimiter1" = Table.SplitColumn(Table.TransformColumnTypes(#"Added Custom", {{"Index_Group", type text}}, "en-US"), "Index_Group", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Index_Group.1", "Index_Group.2"}),
        #"Removed Columns1" = Table.RemoveColumns(#"Split Column by Delimiter1",{"Index_Group.2"}),
        #"Changed Type4" = Table.TransformColumnTypes(#"Removed Columns1",{{"Index_Group.1", Int64.Type}}),
        #"Removed Columns2" = Table.RemoveColumns(#"Changed Type4",{"Index"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns2", List.Distinct(#"Removed Columns2"[Start_End]), "Start_End", "Leave_Date"),
        #"Renamed Columns3" = Table.RenameColumns(#"Pivoted Column",{{"Index_Group.1", "Group_Index"}})
    in
        #"Renamed Columns3"

    Thanks a lot for the hints. They have reallly helped me out.