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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
vertokite
Frequent Visitor

Using Windows environment variable in a PowerBI desktop parameter

Hello

I'm trying to use the windows environment variable %USERNAME% as part of a parameter to define source setting.

vertokite_0-1679948950407.png

The source data line in the editor looks like this:  source = Excel.Workbook(File.Contents(#"targetfc" & "\xxxxx.xlsx"), null, true),

 

I have tried to use forward and backward slashes. I keep getting the same error:

vertokite_1-1679949266687.png

Is it even possible to use the windows environment variables within PowerBI desktop?

 

I appreciate your ideas, Thanks, Verto

 

 

4 REPLIES 4
ArtiSt
New Member

You may try somthing like 

let
re=(string,regex,flags)=>Web.Page(
"<script>
document.write(('"&string&"').match('"&regex&"','"&flags&"'));
</script>")[Data]{0}[Children]{0}[Children]{1}[Text]{0}
in
re(Text.Combine(Folder.Contents("C:\Users")[Name], ","),"p\\d{6}", "g")

 With RegEX you may filter the part of the path from the CSV generated by Text.Combine

see: RegEx in Power BI and Power Query in Excel with Java Script – (thebiccountant.com)

Rifter
Frequent Visitor

I have yet to get this to work right.  I don't know why we can't put in %USERNAME% to dynamically shift document locations.  I have hundreds of students that access a PBIX file that is created from an Excel file each sememster.  Getting them to know where to put the excel file is very painful.

 

What I do, is I create two parametmers.  FilePath and Filename.  I put them in a group called File Location. (1)

 

Curernt Value for FilePath is C:\ITM310  Filename is name of the excel file used to build the PBIX file.  Put a \ before the file name.  (In my instance the file name doesn't change, but the folder name does.)

 

Then, for the source (2) in each table, I go in and set the excel workbook to Advanced (3) and use the Filepath Parts.  I pull the parameters for FilePath and Filename.  It then puts them together: {FilePath}{Filename} .(4)

 

Rifter_0-1680653758767.png

It's not the best method, but it is bette than nothing.  This is something I have been trying to rectify for a few years now.  

 

 

 

 

 

marcelsmaglhaes
Super User
Super User

Hey @vertokite  try type "=Environ("VariableName")" nn the "Current Value" field. 

***(replace "VariableName" with the name of the Windows environment variable you want to use).

Kind Regards,
Marcel


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



Hi Marcel and many thanks for taking the minute to help me out.  Since I'm still kind of a beginner I'm not entirely sure to understand your suggestion.  What would I type in the parameter for the filepath:  

=Environ("USERPROFILE")\PowerBI\      which should resolve to     C:\user\"username"\PowerBI.

I cant get this to work.  Maybe I misunderstood you.  Thanks again

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.