• 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
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member
You are here: Home

vba course banner

Lost password?
sp_Search
Advanced Search|Last Search Results
Advanced Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search

Please confirm you want to mark all posts read

Mark all topics read

sp_MobileMenu Actions
Actions
sp_LogInOut
Log In
sp_Search

Search Forums

sp_RankInfo
Ranks Information
Avatar

New/Updated Topics

General Excel Questions & Answers

  Item Analysis- Calculation of the Difficulty Index& Inde…

  Formula for Drawdown

Dashboards & Charts

  Secrets to Building Excel Dashboards based on Non-financial …

VBA & Macros

  Add ".xlsb" to existing Macro - IF Statement

Power Query

  Office 365 changes format of dates to General

  Power Query, Replace Text not working for specific text

  Generate a unique passcode accross records in powerquery

  How can I convert dates to weekdays

  how can one validate a student id against a list of 'accre…

Excel Dashboards

  Excel iMac problem Pivot-Charts

Power Query

  PDF document with multiple pages

Xtreme Pivot Tables

  Ordering columns in a pivot table

Power BI

  Lesson 2.01

  Power BI - 1.03 Dashboard in Minutes

  Power BI - formula

Select Forum

  Rules and Guides

Forum Rules and Guides

  Public Forums - For Registered Users

General Excel Questions & Answers

Dashboards & Charts

VBA & Macros

Power Query

Power Pivot

  Course Members Only

Excel Dashboards

Power Query

Power Pivot

Xtreme Pivot Tables

Excel for Decision Making

Excel for Finance

Power BI

Excel

Word

Outlook

Excel Expert

Excel for Customer Service Professionals

Excel Analysis Toolpak

Excel Tables

Excel for Operations Management

Financial Modelling

Advanced Excel Formulas

Pivot Tables Quick Start

ForumsPower Query
sp_TopicIcon
Power Query Conditional Sum Column
Avatar
Chris Wagner
Posts: 8
Level 0
February 4, 2018 - 5:37 am

1

I have a table that lists transactions. Among other fields, each record lists a description, an account number and an amount.  I want to create a column that gives the sum of all transactions with that particular account number.

For example, if I have five records as follows, how do I create the sum column in power query?

    

Description Amount Account Sum Column
Rent: Room 103  $          150.00 1001 $600.00
Rent: Room 104  $          200.00 1001 $600.00
Rent: Room 105  $          250.00 1001 $600.00
Supplies: Room 103  $            67.00 1002 $90.00
Supplies: Room 104  $            23.00 1002 $90.00
sp_AnswersTopicSeeAnswer
Avatar
Catalin Bombea
Iasi, Romania
Posts: 1826
Level 10
February 4, 2018 - 3:06 pm

2

Hi Chris,

There is a very simple technique you can use for this.

First, here is the query I used, I will explain it:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Description", type text}, {"Amount", Int64.Type}, {"Account", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Account"}, {{"Sum", each List.Sum([Amount]), type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Account] = 1001)),
    #"1001" = #"Filtered Rows"{[Account=1001]}[Sum],
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Sum Column", each Table.SelectRows(#"Grouped Rows", each ([Account] = [Account])){[Account=[Account]]}[Sum])
in
    #"Added Custom"

All I did is to group rows by account (this will provide the sum), applied a filter on Account column to display only one account, and in the Sum column-right click on that value and choose Drill Down, this will create the step #"1001" = #"Filtered Rows"{[Account=1001]}[Sum],

I did these steps just to get the right syntax I need to use in the last step, when I add a new column with our sum. In the formula for the new column, I simply replaced the parameter I used for the filter with a dynamic reference to the Account column, combining it with the next step(drill down):

Table.SelectRows(#"Grouped Rows", each ([Account] = 1001)){[Account=1001]}[Sum]

Table.SelectRows(#"Grouped Rows", each ([Account] = [Account])){[Account=[Account]]}[Sum]

Note that in the last #"Added Custom" step, I referred to the #"Changed Type" step, skipping the steps: #"Filtered Rows" and #"1001", which can even be deleted, As I already said I needed those steps just to obtain the correct syntax for my formula.

Hope the colors I used will help you understanding what I did.

sp_AnswersTopicAnswer
Avatar
Chris Wagner
Posts: 8
Level 0
February 5, 2018 - 9:56 am

3

Hi Catalin,

Thanks for such a detailed answer.  I appreciate the work you put into responding to my question.  The color coding and attached spreadsheet are most helpful.Smile

Avatar
leroy holmes
Posts: 6
Level 0
March 21, 2019 - 11:06 am

4

Awesome. Thanks.

To assist I made a 'dummy' table and renamed the approriate columns & the table to match your code.

I then copied the code across and bingo it worked. Last thing to do was convert it back to my actual column names etc

🙂

Forum Timezone:
Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Orlando Menes, Alicia Greynolds, Lee Mapes
Guest(s) 7
Currently Browsing this Page:
1 Guest(s)

Devices in use: Desktop (9), Phone (1)

Forum Stats:
Groups: 3
Forums: 24
Topics: 6369
Posts: 27852
Member Stats:
Guest Posters: 49
Members: 32359
Moderators: 3
Admins: 4
© Simple:Press

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.