View source: R/fabric_pbi_dax_query.R
| fabric_pbi_dax_query | R Documentation |
High-level helper that authenticates against Azure AD, resolves the workspace & dataset from a Power BI (Microsoft Fabric) XMLA/connection string, executes a DAX statement via the Power BI REST API, and returns a tibble with the resulting data.
fabric_pbi_dax_query(
connstr,
dax,
tenant_id = Sys.getenv("FABRICQUERYR_TENANT_ID"),
client_id = Sys.getenv("FABRICQUERYR_CLIENT_ID", unset =
"04b07795-8ddb-461a-bbee-02f9e1bf7b46"),
include_nulls = TRUE,
api_base = "https://api.powerbi.com/v1.0/myorg"
)
connstr |
Character. Power BI connection string, e.g.
|
dax |
Character scalar with a valid DAX query (see example). |
tenant_id |
Microsoft Azure tenant ID. Defaults to |
client_id |
Microsoft Azure application (client) ID used to authenticate. Defaults to
|
include_nulls |
Logical; pass-through to the REST serializer setting. Defaults to TRUE. If TRUE, null values are included in the response; if FALSE, they are omitted. |
api_base |
API base URL. Defaults to "https://api.powerbi.com/v1.0/myorg". 'myorg' is appropriate for most use cases and does not necessarily need to be changed. |
In Microsoft Fabric/Power BI, you can find and copy the connection string by going to a 'Semantic model' item, then go to 'File' -> 'Settings' -> 'Server settings'. Ensure that the account you use to authenticate has access to the workspace, or has been granted 'Build' permissions on the dataset (via sharing).
AzureAuth is used to acquire the token. Be wary of
caching behavior; you may want to call AzureAuth::clean_token_directory()
to clear cached tokens if you run into issues
A tibble with the query result (0 rows if the DAX query returned no rows).
# Example is not executed since it requires configured credentials for Fabric
## Not run:
conn <- "Data Source=powerbi://api.powerbi.com/v1.0/myorg/My Workspace;Initial Catalog=SalesModel;"
df <- fabric_pbi_dax_query(
connstr = conn,
dax = "EVALUATE TOPN(1000, 'Customers')",
tenant_id = Sys.getenv("FABRICQUERYR_TENANT_ID"),
client_id = Sys.getenv("FABRICQUERYR_CLIENT_ID")
)
dplyr::glimpse(df)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.