Forum Discussion
Detecting Power BI Report Server Environment (Dev or Prod) Using DAX
- 9 months ago
Hi ArwaAldoud,
There isn’t a supported way for a Power BI report on Report Server to read its own Web Portal URL or server name from DAX. DAX has no concept of the hosting URL, and PBIRS doesn’t surface that as a model property. The usual pattern is to bring an “environment” value in through your data (SQL, M parameter, etc.) and reference it with a simple DAX measure. Microsoft Learn confirms URL-based filtering for PBIRS but not reading the URL inside the report; community threads also note DAX can’t access the browser/URL directly. Example discussion.
Put the environment in your data and read it with DAX.
If your report hits SQL Server, expose a single-row view that returns your environment based on the server you’re connected to. SQL Server provides @@SERVERNAME, which you can map to “Dev” vs “Prod.” (Docs: @@SERVERNAME)
Example SQL view
CREATE VIEW dbo.vEnvironment AS SELECT CASE WHEN @@SERVERNAME LIKE '%DEV%' THEN 'Dev' WHEN @@SERVERNAME LIKE '%PROD%' THEN 'Prod' ELSE 'Unknown' END AS EnvironmentName;Load dbo.vEnvironment (1 row) into your model and create:
DAX
Environment = VAR env = SELECTEDVALUE( vEnvironment[EnvironmentName], "Unknown" ) RETURN env
Use [Environment] in cards/titles/conditional formatting. When the same PBIX points at Dev vs Prod SQL, the measure changes automatically.
If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.
- 9 months ago
We’ve managed to solve this
Since Power BI Report Server doesn’t provide a built-in way to detect the hosting environment (Dev or Prod) through DAX, we created a table in each environment’s database ( Dev DB and Prod DB) that includes:
Report Name | Environment | URL (base path + report path)
Before uploading a report, we switch the data source to the correct environment — for example, Prod when publishing to production, and Dev when working in development.
Then, within the report, I use a measure to dynamically pick the right URLs based on the report name.
It required adding the report URLs manually, but it works.
We’ve managed to solve this
Since Power BI Report Server doesn’t provide a built-in way to detect the hosting environment (Dev or Prod) through DAX, we created a table in each environment’s database ( Dev DB and Prod DB) that includes:
Report Name | Environment | URL (base path + report path)
Before uploading a report, we switch the data source to the correct environment — for example, Prod when publishing to production, and Dev when working in development.
Then, within the report, I use a measure to dynamically pick the right URLs based on the report name.
It required adding the report URLs manually, but it works.