• 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 based on a date range (customer recent orders)|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Sum based on a date range (customer recent orders)|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 based on a date range (customer…
sp_PrintTopic sp_TopicIcon
Sum based on a date range (customer recent orders)
Avatar
Peter Philip

New Member
Members
Level 0
Forum Posts: 1
Member Since:
April 30, 2019
sp_UserOfflineSmall Offline
1
April 30, 2019 - 12:41 pm
sp_Permalink sp_Print

I have a table of customer orders with date and amount, I want to create a summary grouped by the customer name that shows the orders in the last month and the orders for the 3 months previous to that to flag which customers are currently buying, but haven't bought this month.

I've created a summary that can show the total amount ordered and know how to get the first and last date but the SUM based on the last 30 days of orders has me stumped.  I know how to do this in SQL with a WHERE clause and this is probably an easy task but I'm a Power Query newbie.  Thanks!

Here's my query but I feel like doing this as a group is not the right way to achieve what I'm looking for...

let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Order Date", type date}, {"Amount", Currency.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Customer"}, {{"Total Sales", each List.Sum([Amount]), type number}, {"First Order", each List.Min([Order Date]), type date}, {"Last Order", each List.Max([Order Date]), type date}})
in
#"Grouped Rows"

Avatar
Mynda Treacy
Admin
Level 10
Forum Posts: 4447
Member Since:
July 16, 2010
sp_UserOfflineSmall Offline
2
May 1, 2019 - 8:08 am
sp_Permalink sp_Print

Hi Peter,

Welcome to our forum.

This isn't a job for Power Query. Power Query is for getting and cleaning the data which you then load to an Excel Table or the Power Pivot data model for the type of analysis you describe.

For example, you could do this analysis in a PivotTable. I wasn't able to make use of your file because the query's source table is no longer in the file, so the query returns an error. I figure you removed it because it contained sensitive information, but next time you could just remove/modify the data slightly to anonymize it.

This post provides an example of using a PivotTable with Slicers to group data into the last 12 months and current 12 months, which you could modify for the previous 3 months and last 30 days.

I hope that points you in the right direction. Please come back if you have further questions.

Mynda

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Roslyn Finlayson, s Ramchandran, Shanna Henseler
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:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6210
Posts: 27236

 

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