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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
aammontecas
New Member

Convert name to id for use in m query

Hello, I am using Query Parameters to format a call to an API to return data for a given trackingId.

 

I have a table with userName, trackingId. I want to call an API to populate a new table, the input to that call is trackingId

 

"https://apibaseurl.com" & "/application?trackingId=" & Uri.EscapeDataString(trackingId)"

 

I want a user to be able to enter a userName in the parameter, but have the query use the trackingId of that userName

2 REPLIES 2
aammontecas
New Member

I have created the lookup table called device containing alias(name), mac(id), and the list of alias called l_device_username, using that query I created a parameter trackingUser.

 

I added this to the query

 

#"device" = {[alias=#"trackingUser"]}[mac],
Source = Json.Document(Web.Contents("https://apibaseurl" & "/application?trackingId=" & Uri.EscapeDataString(#"device") & "&startTime=" & Uri.EscapeDataString(startTime) & "&endTime=" & Uri.EscapeDataString(endTime), [Headers=[#"Content-Type"="application/json", #"Api-Key"="*"]])),
content = Source[content],

 

But get this error:

 

Expression.Error: We cannot apply field access to the type List.
Details:
Value=[List]
Key=mac

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @aammontecas 

 

I would approach this problem by creating a Table with two columns.  Name and ID.

A List of Name can be created using the "Name" column.  This List of Names can be used in the Parameter settings.  This is example from the Manage Parameters panel.

DarylLynchBzy_0-1642615899219.png

 

Finally, in the main API call, you can use the "Name" value to search for the "ID" value.  The M script is something like this:

#"Name Table"{[Name=#"Parameter Value"]}[ID]


This seraches for the Table, finds the row number for the parameter name and then returns the ID value.


 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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