Filter by Max Value of a column

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

This is my current script/applied steps to import data from the spreadsheet and reduce it to latest week:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Removed Columns" = Table.RemoveColumns(Source,{"Monday", "Open", "Close",  "Size", "Ribbon", "TimeFrame", "B1", "B2", "B3", "B4", "123 Shape", "1-3 Time Gap", "123 vs Red Pivot", "123 vs Yellow Pivot", "3 Close to Ribbon", "Comment"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Date", type date},{"WeekNum", Int64.Type}, {"Security", type text}, {"Direction", type text}, {"Open", type number}, {"Stop", type number}, {"Target", type number}, {"R", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [WeekNum] = List.Max([WeekNum])),
    #"Filter and Drop WeekNum" = Table.RemoveColumns(#"Filtered Rows",{"WeekNum"})
in
    #"Filter and Drop WeekNum"

Via Source, WeekNum are calculated by today's date so the column is always in descending order.

I believe I've defined the WeekNum column correctly as integer but I think I'm using List.Max incorrectly and guessing a separate function needs to be used?
Error with line: #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [WeekNum] = List.Max([WeekNum]))

Bold part is what I've changed and it's generating error:
Expression.Error: We cannot convert the value 37 to type List.
Details:
Value=37
Type=[Type]


Alternatively, return the value of the last row in WeekNum and filter by that column

Searching online keeps bringing up answers that create another column but I do not think that's needed for this, can anyone help with a suggestion, preference find max of the column?

TIA,
Jack
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Found solution by adapting this:

Power Query:
= Table.SelectRows(#"Changed Type", each [WeekNum] =  List.Max(#"Changed Type"[WeekNum]))
 
Upvote 0
Solution

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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