Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
samw5
Helper II
Helper II

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

1 ACCEPTED SOLUTION

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

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.

@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.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

OK now while the filter would work, how could I possibly (not sure if that can even be done) use that ID value back into the original 2 tables queries?

 

That VAR_ID would need to somehow be inserted into my query. Not sure how to do that.

 

= let Source = Json.Document(Web.Contents("https://api.loganalytics.io/v1/workspaces/VAR_ID/query"

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.