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
ArwaAldoud
Super User
Super User

Detecting Power BI Report Server Environment (Dev or Prod) Using DAX

Hi, 
I want to detect the current environment (Dev or Prod) inside my Power BI report after it's published to Power BI Report Server.
Each environment has a different Web Portal URL:

Dev Server: http://dev-reportserver/Reports/powerbi/...
Prod Server: http://prod-reportserver/Reports/powerbi/...

I need a way to access the Web Portal URL or server name from within the report, ideally using DAX, so I can dynamically determine which environment the report is running in.

In short, you're trying to dynamically determine the hosting environment of a Power BI report using DAX or other internal logic, based on where it's published.

2 ACCEPTED SOLUTIONS
tayloramy
Community Champion
Community Champion

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.

View solution in original post

ArwaAldoud
Super User
Super User

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.

View solution in original post

6 REPLIES 6
ArwaAldoud
Super User
Super User

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.

v-tejrama
Community Support
Community Support

Hi @ArwaAldoud ,


Thank you @tayloramy  the response provided!


Has your issue been resolved? If the response provided by the community member addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.


Thank you for your understanding!

Hi @ArwaAldoud ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.

 

Thank you,

Tejaswi.

tayloramy
Community Champion
Community Champion

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.

Hi @tayloramy 

Thanks! We followed a similar approach using a SQL view — but instead of relying on @@SERVERNAME, we maintain a metadata table (report name, environment, and URL)

Thomaslleblanc
Super User
Super User

I would create a table in my source database (one for dev and one or prod), and have a config table to store these settings. Then the table can be part of the model for a DAX column or measure.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.