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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ArwaAldoud
Contributor II

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 REPLIES 2
Thomaslleblanc
Contributor

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.

tayloramy
Contributor

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.

Helpful resources

Announcements
Users online (11,584)