Hello,
I'm somewhat new to the Power Query/Power Pivot world. I have a situation where I'm creating a report and need to import from a folder, for a set of four files, the most recent version of each file and the previous version. Any time there is a new version of the files they will all have the same created date. However, the most recent files may not be in the current week or month the report will be run and the period of time since the previous version of the files is not always on a consistent basis (i.e. should be weekly, but not always so). Therefore, I wanted to create code that could dynamically determine the two most recent created dates. I was hoping to somehow leverage List.LastN to filter down to the last two created dates. I converted the created dates to "date" type to get rid of the creation time complications. I started with a date filter of "is latest" hoping to be able to modify that code, but I just can't figure it out. How would I go about getting all the files for the two most recent created dates?
Below is the code from the advanced editor. I'd like to modify or replace the #"Filtered Rows1" line... Unfortunately it wasn't as easy as just replacing List.Max with a List.LastN(#"Changed Type"[Date created],2)
Thanks for any help or insight.
I'm somewhat new to the Power Query/Power Pivot world. I have a situation where I'm creating a report and need to import from a folder, for a set of four files, the most recent version of each file and the previous version. Any time there is a new version of the files they will all have the same created date. However, the most recent files may not be in the current week or month the report will be run and the period of time since the previous version of the files is not always on a consistent basis (i.e. should be weekly, but not always so). Therefore, I wanted to create code that could dynamically determine the two most recent created dates. I was hoping to somehow leverage List.LastN to filter down to the last two created dates. I converted the created dates to "date" type to get rid of the creation time complications. I started with a date filter of "is latest" hoping to be able to modify that code, but I just can't figure it out. How would I go about getting all the files for the two most recent created dates?
Below is the code from the advanced editor. I'd like to modify or replace the #"Filtered Rows1" line... Unfortunately it wasn't as easy as just replacing List.Max with a List.LastN(#"Changed Type"[Date created],2)
Code:
let
Source = Folder.Files("L:\Corrective Actions\New Item Review\New Item Lists"),
#"Filtered Rows" = Table.SelectRows(Source, each Text.Contains([Folder Path], "Source Reports") and Text.Contains([Folder Path], Text.From(Date.Year(DateTime.LocalNow())))),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows",{{"Date Created", type date}}),
#"Filtered Rows1" = Table.SelectRows(#"Changed Type", let Latest = List.Max(#"Changed Type"[Date created]) in each [Date created] = latest)
in
#"Filtered Rows1"
Thanks for any help or insight.