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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
sm88483
Frequent Visitor

How to automatically filter for max value

I want power query to automatically filter for the most recent date in the date column.

 

The current code is shown below, in the last line of code there is the date field which is manually input, how do I alter it so that it automatically takes the most recent date? Apologies if this is a really simple question. Thanks in advance.

 

let
Source = Sql.Databases("source.com"),
SecDBTest = Source{[Name="SecDBTest"]}[Data],
dbo_Securities2 = SecDBTest{[Schema="dbo",Item="Securities2"]}[Data],
#"Merged Queries" = Table.NestedJoin(dbo_Securities2, {"Security ID"}, Prices1, {"Security"}, "Prices1", JoinKind.LeftOuter),
#"Expanded Prices1" = Table.ExpandTableColumn(#"Merged Queries", "Prices1", {"Date", "Market Price "}, {"Prices1.Date", "Prices1.Market Price "}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Prices1",{{"Prices1.Date", type date}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Prices1.Date] = #date(2022, 6, 23)))
in
#"Filtered Rows"
1 ACCEPTED SOLUTION
wdx223_Daniel
Community Champion
Community Champion

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Prices1.Date] = List.Max(#"Changed Type"[Prices1.Date]))

View solution in original post

4 REPLIES 4
wdx223_Daniel
Community Champion
Community Champion

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Prices1.Date] = List.Max(#"Changed Type"[Prices1.Date]))

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Replace #date(2022, 6, 23) with

Date.From(DateTime.FixedLocalNow())

Thanks for the response. Would that just be filtering for today's date? If so, today's date may not be actually in the dataset yet, I would need it to look at the column and find the largest date that is contained in the dataset.

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Please go ahead with @wdx223_Daniel 's solution. 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Kudoed Authors