Power Query -- List.Sum & Parameter

Comfy

Well-known Member
Joined
Dec 21, 2009
Messages
3,386
I think I'm missing the obvious so would appreciate alittle help.

I'm using the following parameter:


Excel 2010
ABC
3FilterDate
4Month End31/07/2016
_control


dMonths
Rich (BB code):
(myParameter) =>
let
    Source = Excel.CurrentWorkbook(){[Name="dMonths"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Filter", type text}, {"Date", type datetime}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Filter] = myParameter)),
    ReturnParam = Record.Field(#"Filtered Rows"{0}, "Date")
in
    ReturnParam

tFact
Rich (BB code):
MonthEnd = Date.ToText(Date.From(dMonths("Month End")),"dd-MMM-yy"),

My columns headers include the End of Month Date, which is why I'm using this (I also have one for Year End)

The following allows me to append the string:

Rich (BB code):
 #"Removed Other Columns" = Table.SelectColumns(#"Promoted Headers",{"Description", "Plan #(lf)Month ending #(lf)"&MonthEnd, "Actual #(lf)Month ending #(lf)"&MonthEnd, "Variance #(lf)Month ending #(lf)"&MonthEnd, "Plan #(lf)YTD ending #(lf)"&MonthEnd, "Actual #(lf)YTD ending #(lf)"&MonthEnd, "Variance #(lf)YTD ending #(lf)"&MonthEnd, "Plan #(lf)Year ending #(lf)"&YearEnd, "Simple Forecast Year ending#(lf)"&YearEnd, "Forecast Adjustment Year ending#(lf)"&YearEnd, "Adjusted Forecast #(lf)Year ending#(lf)"&YearEnd, "Forecast Variance #(lf)Year ending#(lf)"&YearEnd}),

But I can't use this within List.Sum when grouping:

Rich (BB code):
#"Grouped Rows" = Table.Group(#"Filtered Rows2", {"NewColumn.Sort Order", "NewColumn.Sub Total Heading", "NewColumn.Internal Reporting Header"}, {{"Plan This Month", each List.Sum([#"Plan #(lf)Month ending #(lf)"&MonthEnd]), type number}, {"Actual This Month", each List.Sum([#"Actual #(lf)Month ending #(lf)31-Jul-16"]), type number}, {"Var This Month", each List.Sum([#"Variance #(lf)Month ending #(lf)31-Jul-16"]), type number}, {"Plan YTD", each List.Sum([#"Plan #(lf)YTD ending #(lf)31-Jul-16"]), type number}, {"Actual YTD", each List.Sum([#"Actual #(lf)YTD ending #(lf)31-Jul-16"]), type number}, {"Var YTD", each List.Sum([#"Variance #(lf)YTD ending #(lf)31-Jul-16"]), type number}, {"Annual Plan", each List.Sum([#"Plan #(lf)Year ending #(lf)31-Mar-17"]), type number}, {"Simple Forecast", each List.Sum([#"Simple Forecast Year ending#(lf)31-Mar-17"]), type number}, {"Forecast Adjustment", each List.Sum([#"Forecast Adjustment Year ending#(lf)31-Mar-17"]), type number}, {"Adjusted Forecast", each List.Sum([#"Adjusted Forecast #(lf)Year ending#(lf)31-Mar-17"]), type number}, {"Forecast Var", each List.Sum([#"Forecast Variance #(lf)Year ending#(lf)31-Mar-17"]), type number}}),



The error is highlighted, "Invalid identifier"
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Yes, this is a bit tricky, as you cannot pass any parameters into the square brackets.
You can use Table.SelectColumns instead, there the expression is expected to be a simple text-expression within a list:

List.Sum(Table.ToColumns(Table.SelectColumns(_, {ParameterName})){0})}

(Unfortunately just for this case) it doesn't return the column in list-form, but a table with just one column, so you need to transform that into a list first before you can create the sum.

... would also be interested if there is an easier way to do this.
 
Upvote 0
Thanks for the response.

As a quick fix I renamed the columns to remove the changing date:

Code:
RenameCols = Table.RenameColumns(FilterUnJoinedRows,{{"Plan #(lf)Month ending #(lf)"&MonthEnd, "Plan #(lf)Month ending"}, {"Actual #(lf)Month ending #(lf)"&MonthEnd, "Actual #(lf)Month ending"}, {"Variance #(lf)Month ending #(lf)"&MonthEnd, "Variance #(lf)Month ending"}, {"Plan #(lf)YTD ending #(lf)"&MonthEnd, "Plan #(lf)YTD ending"}, {"Actual #(lf)YTD ending #(lf)"&MonthEnd, "Actual #(lf)YTD ending"}, {"Variance #(lf)YTD ending #(lf)"&MonthEnd, "Variance #(lf)YTD ending"}, {"Plan #(lf)Year ending #(lf)"&YearEnd, "Plan #(lf)Year ending"}, {"Simple Forecast Year ending#(lf)"&YearEnd, "Simple Forecast Year ending"}, {"Forecast Adjustment Year ending#(lf)"&YearEnd, "Forecast Adjustment Year ending"}, {"Adjusted Forecast #(lf)Year ending#(lf)"&YearEnd, "Adjusted Forecast #(lf)Year ending"}, {"Forecast Variance #(lf)Year ending#(lf)"&YearEnd, "Forecast Variance #(lf)Year ending"}}),
    GroupRows = Table.Group(RenameCols, {"NewColumn.Sort Order", "NewColumn.Sub Total Heading", "NewColumn.Internal Reporting Header"}, {{"Plan This Month", each List.Sum([#"Plan #(lf)Month ending"]), type number}, {"Actual This Month", each List.Sum([#"Actual #(lf)Month ending"]), type number}, {"Var This Month", each List.Sum([#"Variance #(lf)Month ending"]), type number}, {"Plan YTD", each List.Sum([#"Plan #(lf)YTD ending"]), type number}, {"Actual YTD", each List.Sum([#"Actual #(lf)YTD ending"]), type number}, {"Var YTD", each List.Sum([#"Variance #(lf)YTD ending"]), type number}, {"Annual Plan", each List.Sum([#"Plan #(lf)Year ending"]), type number}, {"Simple Forecast", each List.Sum([#"Simple Forecast Year ending"]), type number}, {"Forecast Adjustment", each List.Sum([#"Forecast Adjustment Year ending"]), type number}, {"Adjusted Forecast", each List.Sum([#"Adjusted Forecast #(lf)Year ending"]), type number}, {"Forecast Var", each List.Sum([#"Forecast Variance #(lf)Year ending"]), type number}}),
 
Upvote 0

Forum statistics

Threads
1,223,699
Messages
6,173,907
Members
452,536
Latest member
Chiz511

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top