• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pivot Table - Sum of values from a column

mian.tx.00

New Member
Hello experts - I have an excel sheet (see attached). I need to create a pivot report/table. Where I need to report count of different categories( column C - there are 4 categories). The sum for each category should be calculated based on values from Column D for each unique ITEM ID (column A) .

Example:
Item ID 20 has 10 rows, associated with COB, we will pick 6 from column D,
Item ID 21 has 17 rows, associated with COB, we will pick 6 from Column D
Item ID 23 has 12 rows, associated with COHP, we will pick 3 from column D
Item ID 25 has 15 rows, associated with CIT, we will pick 6 from column D
Item ID 26 has 35 rows, associated with TC, we will pick 9 from column D
Item ID 28 has 8 rows, associated with TC, we will pick 2 from Column D

Pivot table should display report as

COB 12 ----- 6 +6
COHP 3
CIT 6
TC 11 ------- 9 +2
Grand Total: 32
 

Attachments

  • Example.xlsx
    10.5 KB · Views: 9
Just for fun adding an alternative with Power Query

- Loading the table into PQ
- using group by 2x
- Using Table.InsertRows() to add the grand total line with a List.Sum().
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Item ID", Int64.Type}, {"VersionNumber", Int64.Type}, {"Category", type text}, {"Applied", Int64.Type}}),
    GroupBy = Table.Group(#"Changed Type", {"Item ID", "Category"}, {{"Count", each List.Min([Applied]), type number}}),
    PivTable = Table.Group(GroupBy, {"Category"}, {{"Count", each List.Sum([Count]), type number}}),
    AddGrandTotal = Table.InsertRows(PivTable,Table.RowCount(PivTable),{[Category = "Grand Total", Count = List.Sum(Table.Column(PivTable,"Count"))]})
in
    AddGrandTotal

Alternative to the last step to add grand total is simply using the table total row of the Power Query result table. And thus possible with some simple mouse clicks.
 

Attachments

  • Example_WithPQ.xlsx
    19.3 KB · Views: 2
Back
Top