• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Sum other columns based on distinct values in first column|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Sum other columns based on distinct values in first column|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QuerySum other columns based on distinct…
sp_PrintTopic sp_TopicIcon
Sum other columns based on distinct values in first column
Avatar
Wuzzy Fuzzy

New Member
Members
Level 0
Forum Posts: 1
Member Since:
June 18, 2020
sp_UserOfflineSmall Offline
1
June 18, 2020 - 7:03 pm
sp_Permalink sp_Print

Hi,

 

I have the following set of data.

Material    Plant       Qty

1001         9000      542

1001         9000      200

1002         9000      599

1001         9001      202

1002         9000      212

1002         9000      300

1001         9003      454

 

Below is the end result i hope to achieve: Distinct Material, showing sum distinct of plant.

I tried Group By + Power Pivot to achieve it. But was hoping if I can do everything in Power Query.

 

Material    Plant                                     Qty

1001         27,004( 9000+9001+9003)     542+202+454

1002         9000                                     599+212+300

 

Any help is greatly appreciated. Thanks in advance!

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
2
June 18, 2020 - 9:26 pm
sp_Permalink sp_Print

Hi,

You desired display not very clear (what is 27,004( 9000+9001+9003) ?)

Attached is the power query output,  please take a look,  if it is not what you want,  please attached a sample output of final table

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Material", Int64.Type}, {"Plant", Int64.Type}, {"Qty", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Material", "Plant"}, {{"Total Qty", each List.Sum([Qty]), type number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Material", Order.Ascending}, {"Plant", Order.Ascending}})
in
#"Sorted Rows"

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1518
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
3
June 18, 2020 - 10:40 pm
sp_Permalink sp_Print

Hi,

The total for Plant where Material is 1001 should be 36004, and where Material is 1002 it should be 27000?

You haven't said where you get this data from so I've had to enter it as a table in Excel.  You can enter this into the Advanced Editor:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Material", Int64.Type}, {"Plant", Int64.Type}, {"Qty", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Material"}, {{"Plant", each List.Sum([Plant]), type number}, {"Qty", each List.Sum([Qty]), type number}})
in
#"Grouped Rows"

Regards

Phil

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
4
June 19, 2020 - 11:47 am
sp_Permalink sp_Print

Hi,

may be this is what you wanted,   for Plant 1001 9000, two records you only take unique number,  i.e. 9000,  like wise for 1002 9000,  only 9000 was taken.  the M Code as below

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Material", Int64.Type}, {"Plant", Int64.Type}, {"Qty", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Number.ToText([Material])&"-"&Number.ToText([Plant])),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Material", "Custom"}, {{"Count", each List.Sum([Qty]), type number}}),
#"Extracted Text After Delimiter" = Table.TransformColumns(#"Grouped Rows", {{"Custom", each Text.AfterDelimiter(_, "-"), type text}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Extracted Text After Delimiter",{{"Custom", type number}}),
#"Grouped Rows1" = Table.Group(#"Changed Type1", {"Material"}, {{"Count", each _, type table [Material=number, Custom=number, Count=number]}}),
#"Aggregated Count" = Table.AggregateTableColumn(#"Grouped Rows1", "Count", {{"Custom", List.Sum, "Sum of Custom"}, {"Count", List.Sum, "Sum of Count"}}),
#"Renamed Columns" = Table.RenameColumns(#"Aggregated Count",{{"Sum of Custom", "Plant_Qty"}, {"Sum of Count", "Qty"}})
in
#"Renamed Columns"

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Brian Pham, Riny van Eekelen
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
stuart burge
Bruce Tang Nian
Scot C
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Forum Stats:
Groups: 3
Forums: 24
Topics: 6223
Posts: 27295

 

Member Stats:
Guest Posters: 49
Members: 31920
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.