[Python] Not able to execute DAX on PowerBI in .Net through ADOMD Client

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have the below python code which works perfectly on any Workspace by executing the DAX on powerbi Dataset, whereas i converted this in .Net, but its failing and giving Not Found error. Can someone please help here

    Python

    import clr
    clr.AddReference(r"C:\Program Files\Microsoft.NET\ADOMD.NET\160\Microsoft.AnalysisServices.AdomdClient.dll")
    from pyadomd import Pyadomd

    # Power BI connection details
    conn_str = (
    "Provider=MSOLAP;"
    "Data Source=powerbi://api.powerbi.com/v1.0/myorg/WorkSpace1;"
    "Initial Catalog=TEST"
    )


    # Run DAX query
    def run_dax_query(query: str) -> pd.DataFrame:
    with Pyadomd(conn_str) as conn:
    with conn.cursor().execute(query) as cur:
    df = pd.DataFrame(cur.fetchall(), columns=[col.name for col in cur.description])
    return df


    .Net

    public string ExecuteDaxQuery(string daxQuery)
    {
    string workspaceConnection = _config["PowerBI:XmlaConnectionString"];

    using var conn = new AdomdConnection(workspaceConnection);
    conn.Open();

    using var cmd = new AdomdCommand(daxQuery, conn);
    using var reader = cmd.ExecuteReader();

    var results = new List<Dictionary<string, object>>();
    while (reader.Read())
    {
    var row = new Dictionary<string, object>();
    for (int i = 0; i < reader.FieldCount; i++)
    {
    row[reader.GetName(i)] = reader.GetValue(i);
    }
    results.Add(row);
    }

    return System.Text.Json.JsonSerializer.Serialize(results);
    }

    Continue reading...

Compartilhe esta Página