New Member
April 30, 2019
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"
July 16, 2010
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
1 Guest(s)