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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Power Query filter two lists by latest date

Dear All,
I am new to PowerBI and after playing around for 2 days and having fun, I face my first challenge.

 

I have connected a SharePoint Folder, with tons of files in it, where around 15 different excel-inventory-lists are replaced weekly by the same name but with a different date. Unfortunately, I do not have the permission to directly connect to the Database and therefore I have to rely on the Excel Sheets, I have access to.

 

I have the following scenario: 

Excel files beginning with a name and followed by a date.

A-04-04-2022.xlsx

B-04-04-2022.xlsx

C-04-04-2222.xlsx

 

together with the old ones:

 

A-28-03-2022.xlsx

B-28-03-2022.xlsx

C-28-03-2022.xlsx

 

The challenge for me now is, how can I filter in Query Editor, that I receive List A & B which are by date the newest one.

 

I could figure out, how to do the filtering for the lists itself:

 

= Table.SelectRows(#"Filtered Rows", each Text.StartsWith([Name], "A") or Text.StartsWith([Name], "B"))

 

But now I need to align the formula on such way, that from the Date Modified, I get the latest list from both files but I fail with either ending up with nothing or only with one List.

 

I tried several ways and either ended up with only one list or as in the below example with nothing.

 

= Table.SelectRows(Source, let latest = List.Max(Source[Date modified]) in each Text.StartsWith([Name], "A") and [Date modified] = latest or Text.StartsWith([Name], "B") and [Date modified] = latest)

 

I am sure, there is a way, to do so, I just have no clue how.

Can someone please help and guide me?

 

Thank you very much for your support,

Mike

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctQ1MAEhIwMjI72KnOIKpVidaCUnrKLOMFEjZFFHXSMLXQNjDBOwiTpjisYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.StartsWith([Name], "A") or Text.StartsWith([Name], "B")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "DateExtracted", each Date.FromText(Text.BeforeDelimiter(Text.AfterDelimiter([Name],"-"),"."))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Filter", each [DateExtracted]=List.Max(#"Added Custom"[DateExtracted])),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom1", each ([Filter] = true)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"DateExtracted", "Filter"})
in
    #"Removed Columns"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WctQ1MAEhIwMjI72KnOIKpVidaCUnrKLOMFEjZFFHXSMLXQNjDBOwiTpjisYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each Text.StartsWith([Name], "A") or Text.StartsWith([Name], "B")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "DateExtracted", each Date.FromText(Text.BeforeDelimiter(Text.AfterDelimiter([Name],"-"),"."))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Filter", each [DateExtracted]=List.Max(#"Added Custom"[DateExtracted])),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom1", each ([Filter] = true)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"DateExtracted", "Filter"})
in
    #"Removed Columns"

 

Anonymous
Not applicable

Hello @Vijay_A_Verma,
Thank you so much for your reply and sorry for my late reply. I didn't see your message, my bad. I will try that. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.