Search code examples
datatablepowerbipowerqueryaggregation

How to aggregate/group the data from one table and output the result as another table in PowerBI?


I have a Raw Data Table as shown in the screenshot below:

enter image description here

I want to group the data in the raw data table into the Output Table as shown in the screenshot below:

enter image description here

Basically the output table is counting the number of student for each understanding level in different intake. May I know how should I get the output table from the raw data table? I'm still new in Power Query, any help will be greatly appreciated!

This is what I have tried:

enter image description here

Code:

= Table.Group(Source, {"Intake"}, {
        {"Count_Little_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Little Understanding"))), Int64.Type},
        {"Count_General_Understanding", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "General Understanding"))), Int64.Type}, 
        {"Count_Good_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Good Understanding"))), Int64.Type},
        {"Count_Fully_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Fully Understand"))), Int64.Type}
    })

I only able to get the table by individual Topic, not sure how to include other Topic appended below and also add another extra column to label the Topic as shown in my second screenshot. Hope to get some advice/help on how should I modified the code. Thank you/1


Solution

  • I've rebuilt a similar but shorter table:

    enter image description here


    Now we first go into Transform (1), mark the Topic Cols (2) and Unpivot Columns (3).

    enter image description here


    Your table now looks like the following screenshot. Finally, we select the Value column (1), click on Pivot Column (2), select Employee Name (3).

    enter image description here


    Result:

    enter image description here