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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
pavel_severov
Advocate I
Advocate I

Check current environment: "desktop" or "service"

Hello! Is there way to check current environment in Power Query?
I.e. - is it running on "desktop" or "service"?

The reason I'm asking - I want my report to automatically use different data sources, depending: is it working on my PC? or on the server?.

 

1 ACCEPTED SOLUTION
GD_Oz
Frequent Visitor

I've written a function that returns TRUE if Power BI Desktop is in use or FALSE if Power BI Service is used. It works very reliably for me, and I use it to select appropriate Parameters.
------------

// 250426 isDesktop Function
// This function returns True if the current environment is PBI Desktop, or False if it's running in Power BI Service
let
Source = () =>
let
// Get IP info from ipinfo.io
GetIPInfo = try Json.Document(Web.Contents("https://ipinfo.io/json")) otherwise null,
Org = if GetIPInfo <> null then Record.FieldOrDefault(GetIPInfo, "org", null) else null,

// It's Desktop if org is not Microsoft-hosted
isDesktop = Org <> null and not Text.Contains(Org, "Microsoft Corporation")
in
isDesktop
in
Source

View solution in original post

8 REPLIES 8
GD_Oz
Frequent Visitor

I've written a function that returns TRUE if Power BI Desktop is in use or FALSE if Power BI Service is used. It works very reliably for me, and I use it to select appropriate Parameters.
------------

// 250426 isDesktop Function
// This function returns True if the current environment is PBI Desktop, or False if it's running in Power BI Service
let
Source = () =>
let
// Get IP info from ipinfo.io
GetIPInfo = try Json.Document(Web.Contents("https://ipinfo.io/json")) otherwise null,
Org = if GetIPInfo <> null then Record.FieldOrDefault(GetIPInfo, "org", null) else null,

// It's Desktop if org is not Microsoft-hosted
isDesktop = Org <> null and not Text.Contains(Org, "Microsoft Corporation")
in
isDesktop
in
Source

Brilliant, thank you!

My pleasure 🙂

aalev
Frequent Visitor

hello pavel_severov, I have the same need, did you sort it out ?

 

I tried with parameters, but it's not satisfying:

- My M code uses env paramter to select right sources (if env = ...)

- My pbix has env = A

- I publish the pbix, it overwrites the PBI service parameter & triggers a refresh

- As soon as the refresh is finished, I can modify the PBI service parameter to env = B

 

I'm looking for a way without having to update PBI service parameter each time I publish.

Any idea ?

 

Alban

 

Hi aalev,

Unfortunately there is no way to get any environment data from Power BI scripts.
At least I don't know anything about it. I would be happy to be wrong.

Ok, thanks @pavel_severov , I submited a feature request here: 

Power query environment variable to distinguish Power BI Desktop from Power BI Service

Please support with your votes  !

Alban

 

v-juanli-msft
Community Support
Community Support

 

ok

 

Best Regards

Maggie

 

Greg_Deckler
Community Champion
Community Champion

I am not aware of a way to do that. I suppose you could set a query parameter just before you publish it?


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.