cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
a68tbird
Resolver II
Resolver II

Passing Value from Function as Parameter in URL

Hello all -

  I'm trying to pass a value retrieved from a function into an API url as a required parameter.  The function returns a number (the List ID).  The API call in M is as such:

= Json.Document(Web.Contents("https://core-base.azurewebsites.net/api/mailer/messages/90/95"), [ApiKeyName="api_key"]))

 

What I need to do is make this dynamic by replacing that last value, the List ID (95) with the value retrieved in the function.  If I concatenate the name of the function I get an error:

We cannot apply operator & to types Text and Function.

If I wrap the function in Number.ToText(), then the error becomes:

We cannot convert a value of type Function to type Number.

 

I created a test parameter with a fixed value and it works fine.  So, if I could somehow change that function output into a parameter, I do believe it will work.  

Anyone have any ideas? Or perhaps a different way to approach?

 

Thank you!

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @a68tbird ,
you need to call that function and not simply reference it.
Please try something like this:
Number.ToText(YourFunctionName())

If your function requires parameter(s), you have to pass them into the red brackets:
Number.ToText(YourFunctionName(YourParameter))

But in any case: You need the brackets to call the function.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Super User
Super User

Hi @a68tbird ,
you need to call that function and not simply reference it.
Please try something like this:
Number.ToText(YourFunctionName())

If your function requires parameter(s), you have to pass them into the red brackets:
Number.ToText(YourFunctionName(YourParameter))

But in any case: You need the brackets to call the function.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors
Top Kudoed Authors