When loading data from Power Query the path varies according to how the user logs in (virtually, locally, etc.).
I am unable to pass the correct path to Power Query. I first select the most recent user and then their path (there might be more than two different paths), so far I have:
let
Source = Folder.Content("C:/Users"),
#"sort_user_table" = Table.Sort(Source, {{"Date accessed", Order.Descending}}),
User = Table.Range(#"sort_user_table",1,1)[Name]{0},
user_path = if Folder.Files("C:\Users\"& User & "path1" <> null
then
Folder.Files("C:/Users"& User & "path2"
else null,
#Sorted Rows" = Table.Sort(user_path,{{"Name", Order.Descending}}),
Keep60files = Table.FirstN(#Sorted Rows",60),
Custom1 = Binary.Combine(Keep60files[Content]),
#Import CSV" = Csv.Document(Custom1, [Delimiter=",", Columns=6, Encoding=1252, QuoteStyle=QuoteStyle.None])
.
.
.
in
#"Sorted Rows1"
Any help would be appreciated
Table.Buffer() is a work around to getting try ... otherwise to work for Folder.Files()
let
username="temp",
Source =
try Table.Buffer(Folder.Files("C:\"&username&"3")) otherwise
try Folder.Files("C:\"&username&"13") otherwise
try Folder.Files("C:\"&username&"2") otherwise
#table({"Content","Name","Extension","Date accessed","Date modified","Date created","Attributes","Folder Path"},{}) //blanktable
in Source