Power Query - Loading a file

Highlighted
Frequent Visitor

I would like to know if it is possible to load a file from the Downloads folder, but use a path that does not use the name of the user profile.

 

Instead of: c:\users\Philip\downloads\file.csv

 

the path would look like c:\users\%USERPROFILE%\downloads\file.csv

 

The idea is anyone in my team would be able to update the query after downloading the 

1 Reply
Highlighted

@philthomasp 

There are 4 trick to get username described here 4 ways to get USERNAME in Power Query That is 3 years old post but still actual. 

Most simple way is to take user who accessed the User folder last, practically always that will current user.

Script is like

let 
     Users = Folder.Contents("C:\Users"), 
     CurrentUser = Table.FirstN(
          Table.Sort(Users,{{"Date accessed", Order.Descending}}),1)[Name]{0},
     GetFile = Csv.Document(
          File.Contents(
               "c:\Users\" &
               CurrentUser &
               "\Downloads\filename.csv"
          ),
          [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.None]
     )
in 
     GetFile

but that only works Downloads folder was not moved into other location for concrete user.