Forum Discussion
Creating "variable" for input query
I am trying to figure out if it would be possible to create a variable in my PowerBI query to replace a portion of my query.
What I'm ultimately trying to do, is to have a popdown menu in my PowerBI report that allows me to select the tenant name which associates with a particular tenantID.
I created a new table that contains "Tenant Name" and "TenantID fields" and added a slicer to select the Tenant.
What I'd like to do next is if "Tenant Name X" is selected on the slicer, have the TenantID fetched from that table and replaced in my query so that the correct data can be pulled.
Now sure if that's possible like it would in SQL but am hoping that something similar can be setup.
= let Source = Json.Document(Web.Contents("https://api.loganalytics.io/v1/workspaces/TENANTID/query",
[Query=[#"query"="WaaSDeploymentStatus",#"x-ms-app"="OmsAnalyticsPBI",#"timespan"="all",#"prefer"="ai.response-thinning=true"],Timeout=#duration(0,0,4,0)])),
TypeMap = #table(
{ "AnalyticsTypes", "Type" },
{
{ "string", Text.Type },
{ "int", Int32.Type },
{ "long", Int64.Type },
{ "real", Double.Type },
{ "timespan", Duration.Type },
{ "datetime", DateTimeZone.Type },
{ "bool", Logical.Type },
{ "guid", Text.Type }
}),
DataTable = Source[tables]{0},
Columns = Table.FromRecords(DataTable[columns]),
ColumnsWithType = Table.Join(Columns, {"type"}, TypeMap , {"AnalyticsTypes"}),
Rows = Table.FromRows(DataTable[rows], Columns[name]),
Table = Table.TransformColumnTypes(Rows, Table.ToList(ColumnsWithType, (c) => { c{0}, c{3}}))
in
Table
- Anonymous5 years ago
Hi samw5 ,
Please create query parameter to change the data source dynamically instead of using slicer selection, you can refer the following documentations to achieve it.
Change the Source of Power BI Datasets Dynamically Using Power Query Parameters
Dynamic Web.Contents() and Power BI Refresh Errors
Web.Contents with dynamic file URL
Best Regards
Rena
5 Replies
- amitchandakSuper User
samw5 , not clear, refer if this can help
https://www.biinsight.com/power-bi-desktop-query-parameters-part-1/
- samw5Helper II
So i have data from 2 tables being fetched from Azure.
I created a 3rd table with Name and ID columns.
What I'm trying to do, is to setup a slicer on my visualization that will allow me to pick the "Name", then use the "ID" as a variable into my 2 other tables.- Greg_DecklerCommunity Champion
samw5 - So, you should just have to use this in your measure:
VAR __ID = MAX('Third Table'[ID])
Since you select a name, that will filter that third table to that name so the MAX will get the associated ID.