Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I run my own DAX or MDX queries against Power BI?

Tags:

powerbi

dax

mdx

I have a data model in Power BI desktop. I'd like to publish it to the server, but I'd also like to have an internal report run MDX (or DAX) queries against it. Is this possible? Can I just create a connection string and connect to Power BI like to a SSAS Cube? Maybe using the REST APIs?

Edit: Thanks for your answers. Kyle gave me the best answer to my question, so I accepted his, but all of you made me clear that I'd better just use SSAS. This is what I did, with some hassle of seeing up HTTP bridge, but it works like a charm now.

like image 220
Teun D Avatar asked Feb 08 '23 01:02

Teun D


2 Answers

It actually is possible in a literal sense - every time you run PowerBI, it creates a behind-the-scenes instance of SSAS Tabular that you can connect to and run queries against. Obviously this isn't directly supported by Microsoft, but I leave these steps in case anyone else wants to know how:

  1. Navigate to %user%/AppData/Local/Temp/Power BI Desktop
  2. Open your PowerBI Desktop model
  3. A new folder will appear in the temp folder, inside that is a folder called AnalysisServicesWorkspace1111111111 (numbers at end are random)
  4. Inside that folder is a file, msmdsrv.port.txt, which contains the port number (portnum) on which the SSAS Tabular model is running
  5. You can open SSMS and connect to Analysis Services server localhost:portnum
  6. The specific database instance you can find either via SSMS or the name of the GUID folder in the workspace folder (it'll be something like "33df46dd-8c77-46eb-bf01-8d545f626723.0.db")
  7. Or you can use this as the server / catalog in an SSAS connection string i.e.

Provider=MSOLAP.5;Integrated Security=SSPI;Persist Security Info=True;
Initial Catalog=databasename;Data Source=localhost:portnum;
MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error

Also, for devs of note, inside that *.db folder is a SQLite database which contains all the PowerBI model metadata, you can modify it via code and have it persist as long as you do something trivial in the UI such as select add calculated column and then click away.

like image 179
Kyle Hale Avatar answered Mar 05 '23 03:03

Kyle Hale


To my knowledge this is not possible. Whether there is a workaround or not, I don't know.

You're probably better served using SSAS and connecting to a model in that both from Power BI with the AS Connector and for whatever DAX queries you need to run against it.

like image 39
greggyb Avatar answered Mar 05 '23 04:03

greggyb