How to calculate averages using power query in excel

Paula Sutcliffe 0 Reputation points
2025-02-04T10:08:14.75+00:00

I want to calculate the average of the grades for each student across all their modules. (This data is psuedonymised).

lawps_0-1738620083781

But I want to make it so that a new line is inserted under each set of the same student, like this:lawps_1-1738620231987

Is this possible? Many thanks! Paula

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
2,149 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jiajing Hua-MFST 14,495 Reputation points Microsoft Vendor
    2025-02-05T02:52:43.2233333+00:00

    Hi @Paula Sutcliffe

    Please check whether following steps are helpful, there would be an extra column to get the average numbers:

    • Copy and paste the original query to create a new one. User's image
    • Then select the Table1(2), click Home tab > Group By. The grouping by is set to: ID and Last Name. Choose "Average" for Operation and select "Final Grade Code" column. User's image
    • You will get following results. User's image
    • Find "Append Queries" in Home tab, click it and choose " Append Queries as New". Append these 2 queries. User's image
    • Sort ID and other columns to get the order that you need. User's image

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. riny 260 Reputation points
    2025-02-07T11:07:29.6466667+00:00

    No real need for three separate queries or adding a new column. You can do all in one go. For example, the M-code below takes the blue table ("Table1") to the green one.

    User's image

    let
    
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    
    GroupAverage = Table.Group(Source, {"ID"}, {{"Grade", each List.Average([Grade]), type number}}),
    
    AddLabel = Table.AddColumn(GroupAverage, "Custom", each [ID]&" Average"),
    
    Remove = Table.RemoveColumns(AddLabel,{"ID"}),
    
    Rename = Table.RenameColumns(Remove,{{"Custom", "ID"}}),
    
    Append = Table.Combine({Rename, Source}),
    
    Sort = Table.Sort(Append,{{"ID", Order.Ascending}}),
    
    ReorderCols = Table.ReorderColumns(Sort,{"ID", "LastName", "Module", "Grade"}),
    
    ChangedType = Table.TransformColumnTypes(ReorderCols,{{"Grade", Int64.Type}})
    
    in
    
    ChangedType
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.