• 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

Conditional sum based on monthly data|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Conditional sum based on monthly data|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 QueryConditional sum based on monthly da…
sp_PrintTopic sp_TopicIcon
Conditional sum based on monthly data
Avatar
Alexios Vrotsos

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
July 16, 2020
sp_UserOfflineSmall Offline
1
July 16, 2020 - 5:00 am
sp_Permalink sp_Print

Hello,

I have forecast and demand data for certain products for each month for 12 months. There hundreds of products, so for each month there are hundreds of rows with the forecast/demand data. I am calculating the difference between the actual demand data and the forecast data and wish to display a column that shows the total summed difference for each month. So, for all the products demanded in the month of 5/1/2015, the column will display the total difference between the forecast data and the actual demand for each product during that month. Any help would be appreciated. I will also gladly provide any additional needed information. 

 

Thanks in advance!

sp_AnswersTopicSeeAnswer See Answer
Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4448
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
July 16, 2020 - 9:27 am
sp_Permalink sp_Print

Hi Alexios,

Welcome to our forum! This should be done in the PivotTable rather than Power Query. If you want to share a sample Excel file we can help you further.

Mynda

Avatar
Alexios Vrotsos

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
July 16, 2020
sp_UserOfflineSmall Offline
3
July 16, 2020 - 10:19 pm
sp_Permalink sp_Print sp_EditHistory

Hello Mynda,

I appreciate the response. However, I am interested in a solution that can be done within Power Query. I will provide a sample text example below.

 

period          part         demand          forecast         variance       TOTAL VARIANCE BY MONTH

5/1/2015        A                  10                   9                    1                            4

5/1/2015        B                   5                    7                    2                            4

5/1/2015        C                   5                    6                    1                            4

6/1/2015        A                   3                    3                    0                            7

6/1/2015        B                   8                    2                    6                            7

6/1/2015        C                   7                    6                    1                            7

7/1/2015        A                   7                    2                    5                           14

7/1/2015        B                   6                    9                    3                           14

7/1/2015        C                   4                    10                  6                           14

 

I hope the formatting is clear. The column on the far right is the column I wish to generate within Power Query. 

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
July 17, 2020 - 5:18 am
sp_Permalink sp_Print sp_EditHistory

11.jpgImage Enlarger

Hi Alexios,

It's not recommended to do that in PQ, it's better to make the aggregations in a pivot table, see image attached. The table you have is perfect for that.

If you still need that, use the query below:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"period ", type datetime}, {"part ", type text}, {" demand ", Int64.Type}, {"forecast ", Int64.Type}, {" variance ", Int64.Type}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([#"period "]), Int64.Type),
#"Inserted Month" = Table.AddColumn(#"Inserted Year", "Month", each Date.Month([#"period "]), Int64.Type),
#"Renamed Columns" = Table.RenameColumns(#"Inserted Month",{{" variance ", "variance"}}),
#"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", (x)=> List.Sum(Table.SelectRows(#"Renamed Columns", each _[Year]=x[Year] and _[Month]=x[Month])[variance]))
in
#"Added Custom"
sp_PlupAttachments Attachments
  • sp_PlupImage 11.jpg (46 KB)
sp_AnswersTopicAnswer
Answers Post
Avatar
Alexios Vrotsos

Active Member
Members
Level 0
Forum Posts: 3
Member Since:
July 16, 2020
sp_UserOfflineSmall Offline
5
July 17, 2020 - 5:34 am
sp_Permalink sp_Print sp_EditHistory

Hello Catalin,

I appreciate the response. Thank you everybody for the assistance. I will try the attached query, and make the aggregation in a Pivot Table.

Thanks,

Alexios

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Chris Warren
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
Forum Stats:
Groups: 3
Forums: 24
Topics: 6215
Posts: 27248

 

Member Stats:
Guest Posters: 49
Members: 31897
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.