L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Démarrage rapide : Exécuter votre première requête DAX
Dans ce guide de démarrage rapide, vous vous authentifiez à Power BI, exécutez une requête DAX sur un modèle sémantique et désérialisez la réponse flèche dans une structure de données locale.
Prerequisites
Un espace de travail Power BI avec au moins un modèle sémantique.
Générer et lire des autorisations sur le modèle sémantique.
Inscription d’application Microsoft Entra (ou utiliser l’authentification interactive pour les tests).
using Microsoft.Identity.Client;
var clientId = "YOUR_APP_CLIENT_ID";
var tenantId = "YOUR_TENANT_ID";
var scopes = new[] { "https://analysis.windows.net/powerbi/api/.default" };
var app = PublicClientApplicationBuilder
.Create(clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, tenantId)
.WithRedirectUri("http://localhost")
.Build();
var result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
var accessToken = result.AccessToken;
using System.Net.Http.Headers;
using Apache.Arrow;
using Apache.Arrow.Ipc;
var groupId = "YOUR_WORKSPACE_ID";
var datasetId = "YOUR_DATASET_ID";
var url = $"https://api.powerbi.com/v1.0/myorg/groups/{groupId}"
+ $"/datasets/{datasetId}/executeDaxQueries";
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
var body = new StringContent(
"""{"query": "EVALUATE TOPN(5, 'DimProduct')"}""",
System.Text.Encoding.UTF8,
"application/json");
var response = await client.PostAsync(url, body);
response.EnsureSuccessStatusCode();
using var stream = await response.Content.ReadAsStreamAsync();
using var reader = new ArrowStreamReader(stream);
var batch = await reader.ReadNextRecordBatchAsync();
Console.WriteLine($"Rows: {batch.Length}, Columns: {batch.ColumnCount}");
$groupId = "YOUR_WORKSPACE_ID"
$datasetId = "YOUR_DATASET_ID"
$url = "https://api.powerbi.com/v1.0/myorg/groups/$groupId" +
"/datasets/$datasetId/executeDaxQueries"
$headers = @{
"Authorization" = "Bearer $accessToken"
"Content-Type" = "application/json"
}
$body = @{ query = "EVALUATE TOPN(5, 'DimProduct')" } | ConvertTo-Json
$response = Invoke-WebRequest -Uri $url -Method Post -Headers $headers -Body $body
# Save the binary Arrow stream to a file for inspection
$arrowFile = "result.arrow"
[System.IO.File]::WriteAllBytes($arrowFile, $response.Content)
Write-Host "Arrow stream saved to $arrowFile ($($response.Content.Length) bytes)"
# Print the Arrow schema (column names and types)
print(table.schema)
# Show the first few rows as a pandas DataFrame
print(df.head())
# Access a specific column
print(table.column("ProductName").to_pylist()[:5])
// Print the schema (column names and types)
for (var i = 0; i < batch.Schema.FieldsList.Count; i++)
{
var field = batch.Schema.FieldsList[i];
Console.WriteLine($" {field.Name}: {field.DataType}");
}
// Print the first row's values
for (var i = 0; i < batch.ColumnCount; i++)
{
var column = batch.Column(i);
Console.Write($"{batch.Schema.FieldsList[i].Name}=");
Console.Write(column.GetType().GetMethod("GetValue")?.Invoke(column, new object[] { 0 }));
Console.Write(" ");
}
# Use Python with pyarrow to read the saved Arrow file
python -c @"
import pyarrow as pa
reader = pa.ipc.open_stream('result.arrow')
table = reader.read_all()
print(table.schema)
print(table.to_pandas().head())
"@
Nettoyer les ressources
Si vous avez créé une inscription d’application Microsoft Entra uniquement pour les tests, accédez au portail Azure et supprimez-le. Les jetons d’accès expirent automatiquement et n’ont pas besoin de révocation manuelle.