Code: Select all
import pandas as pd
from azure.identity import InteractiveBrowserCredential
from sys import path
path.append(r'C:\Program Files\Microsoft.NET\ADOMD.NET\150')
from pyadomd import Pyadomd
import requests
# Azure AD credentials
# Authenticate and get access token
def get_access_token():
credentials = InteractiveBrowserCredential()
scopes = "https://analysis.windows.net/powerbi/api/.default" # Scope for Power BI XMLA
token = credentials.get_token(scopes)
return token.token
# Get the access token
access_token = get_access_token()
# Connection string with access token
conn_str = f"Data Source=powerbi://api.powerbi.com/v1.0/myorg/MY-%20TM;Initial Catalog=My Dataset;User ID=;Password={access_token};"
# Enter DAX or MDX query
dax_query = """EVALUATE INFO.VARIATIONS()"""
# Output results as pandas dataframe
with Pyadomd(conn_str) as conn:
with conn.cursor().execute(dax_query) as cur:
df = pd.DataFrame(
cur.fetchall(),
columns=[i.name for i in cur.description]
)
print(df)type here