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
C4L84
Advocate II
Advocate II

M Language dynamic max year value

Hi all - total M newbie here!

 

I think this ought to be a simple question to answer but I can't find anything online that helps me in this specific scenario.

 

I need to dynamically filter to max year value.

 

Here's the code as it is:

#"Removed Other Columns" = Table.SelectColumns(Source,{"Date", "Order type", "Amount"}),
#"Merged Queries" = Table.NestedJoin(#"Removed Other Columns", {"Date"}, Calendar, {"Date"}, "Calendar", JoinKind.LeftOuter),
#"Expanded Calendar" = Table.ExpandTableColumn(#"Merged Queries", "Calendar", {"Financial Year"}, {"Calendar.Financial Year"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Calendar", each ([Calendar.Financial Year] = 2021))

 

I changed the last part to:

= Table.SelectRows(#"Expanded Calendar", each ([Calendar.Financial Year] = List.Max([Calendar.Financial Year])))

 

But I am getting this error:

C4L84_0-1626440650100.png

 

How do I filter to the max value of [Calendar.Financial Year]?

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

That was close!  Your 'each' statement causes the second [Calendar.Financial Year] to be a single value, not the entire coulmn as a list.  Here's how it will work:

 

#"Filtered Rows" =  Table.SelectRows(#"Expanded Calendar", let latest = List.Max(#"Expanded Calendar"[Calendar.Financial Year]) in each [Calendar.Financial Year] = latest)

 

--Nate

View solution in original post

2 REPLIES 2
C4L84
Advocate II
Advocate II

Cool! I was wondering how to set it as a variable.

 

Thank you for taking the time to answer, I really appreciate it.

Anonymous
Not applicable

That was close!  Your 'each' statement causes the second [Calendar.Financial Year] to be a single value, not the entire coulmn as a list.  Here's how it will work:

 

#"Filtered Rows" =  Table.SelectRows(#"Expanded Calendar", let latest = List.Max(#"Expanded Calendar"[Calendar.Financial Year]) in each [Calendar.Financial Year] = latest)

 

--Nate

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.