Skip to main content
Microsoft Idea

Power BI

New

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

Vote (25) Share
Alban A's profile image

Alban A on 22 Jan 2023 11:56:12

Hello,


In order to choose the data sources depending on being executed in Power BI Desktop (dev) or Power BI Service (test, prod), we need an environment variable for power query editor.


Use case: When developping under Power BI Desktop, I need to use development data sources (with known data, in small volume). When I publish to Power Bi Service, I want the service to use production data source from the very first refresh.


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

- My M code uses env paramter to select right sources (if env = A then use dev data sources...)

- 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.


Thanks,

Alban

Comments (2)
Alban A's profile image Profile Picture

Dana Frost on 14 Mar 2024 18:56:10

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

This is not exactly what you want but could work...Since Power BI Service hosts are always UTC time zone and most PCs (i.e. Power BI Desktop) will not be set to UTC, you could use TimeZone.Current() to optionally run Power Query Steps.If TimeZone.Current() = 'UTC' then (running on service) else (running on desktop).

Alban A's profile image Profile Picture

Darius Liktorius on 09 Nov 2023 20:35:27

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

There is a very good, applicable use case for this and it should be implemented.Consider an Import mode dataset being authored within Power BI Desktop. The source of data has millions of records. If you save this PBIX out, it will be large in size, containing a relatively large sampling (1m records) of the source data, resulting in a PBIX file of 50MB+Just before saving the PBIX, it would be nice to be able to add a filter to the query, based on a system variable that determines whether the query is running within PBI Desktop and only return the Top 1 row if running in Desktop so you can save the PBIX and only take up 50 Kilobytes, not megabytes. In turn, this filter would NOT apply after being published into the Power BI Service when the Dataset is refreshed with production data.