Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bigreduw64
New Member

LIst Max.N returning null table

I have the following set up and in #"Filtered Rows" I am trying to get the top 4 values returned. With the code I have below, it is returning an empty table and I haven't been able to figure out what is broken.  Any guidance would be greatly appreciated.  Thank you!

let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Fiscal Year Week", type number}, {"Customer Number", Int64.Type}, {"PIM Superclass", type text}, {"Sales $", type number}, {"LY", type number}, {"Var", type number}, {"Var %", type number}, {"AOP", type any}, {"Var2", type any}, {"Cases", type number}, {"LY3", type number}, {"Var4", type number}, {"Var %5", type number}, {"AOP6", type any}, {"Var7", type any}, {"Gross TGP", type number}, {"LY8", type number}, {"Var9", type number}, {"Var %10", type number}, {"AOP11", type any}, {"Var12", type any}, {"Gross TGP %", type number}, {"LY13", type number}, {"Var14", type number}, {"AOP15", type any}, {"Var16", type any}, {"SAGP", type number}, {"LY17", type number}, {"Var18", type number}, {" Var %", type number}, {"SAGP %", type number}, {"LY19", type number}, {"Var20", type number}, {"Net Accounts", Int64.Type}, {"LY21", Int64.Type}, {"Var22", Int64.Type}, {"Var %23", Int64.Type}, {"Gross TGP+PA per Drop", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Fiscal Year Week", "Customer Number"}, {{"Sales $", each List.Sum([#"Sales $"]), type nullable number}, {"Cases", each List.Sum([Cases]), type nullable number}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Fiscal Year Week] = List.MaxN(#"Grouped Rows"[Fiscal Year Week],4))),
#"Grouped Rows1" = Table.Group(#"Filtered Rows", {"Customer Number"}, {{"Sales $", each List.Sum([#"Sales $"]), type nullable number}, {"Cases", each List.Sum([Cases]), type nullable number}}),
#"Divided Column" = Table.TransformColumns(#"Grouped Rows1", {{"Sales $", each _ / 4, type number}}),
#"Divided Column1" = Table.TransformColumns(#"Divided Column", {{"Cases", each _ / 4, type number}}),
#"Renamed Columns" = Table.RenameColumns(#"Divided Column1",{{"Sales $", "4 Week Avg Weekly Sales $"}, {"Cases", "4 Week Avg Weekly Cases"}})
in
#"Renamed Columns"

2 REPLIES 2
amitchandak
Super User
Super User

@bigreduw64 , Try the IN approach using List.Contains

https://gorilla.bi/power-query/in-operator/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak I looked through this and not sure that it will work for my needs as I am trying to do this for a dynamic data set that won't always have the the same max values in the [Fiscal Year Week] column.  

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.