Forum Discussion

melimob's avatar
melimob
Frequent Visitor
6 years ago
Solved

Add Totals Column and Total Row to Pivoted Query for dynamic headers

Hi This is probably really easy but I'm new to G&T and can't figure how to do this all in the query before I load it.   Have a very simple table with columns as: Year, Consultant, and months acro...
  • Anonymous's avatar
    Anonymous
    6 years ago

    It can, replace everything below your source with the code below in the advanced editor.

     

      ColumnNames = List.Buffer(List.Intersect({Table.ColumnNames(Source), {"January","February","March","April","May","June","July","August","September","October","November","December"}})),
        ChangeTypes = Table.TransformColumnTypes(Source,List.Transform(ColumnNames, each { _, type number })),
        AddTotal = Table.AddColumn(ChangeTypes , "Totals", each List.Sum(Record.ToList(Record.SelectFields(_,ColumnNames))))
    in
        AddTotal