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
otravers
Community Champion
Community Champion

Can query parameters be applied to functions?

I have a function that retrieves data from a web API. One of the fields to be passed to the API accepts just two values, "10-Q" and "10-K". I've read the blog posts about parameters and created a parameter list with these two values, but is there a way to use that parameter right in the function definition (i.e. not in a downstream query)? This would work as a form of data validation when the function is invoked.

 

Screenshot below to try and clarify what I mean:

 

 

function-parameter.png 

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals
1 ACCEPTED SOLUTION

Hi @otravers

 

I think that you can put your variable as part of your function in your code below.

 

let
    Source = (ticker as text, FormTypes as text, order as text) as table =>
let
    Source = Json.Document(Web.Contents("https://services.last10k.com/v1/company/" & #"ticker" & "/balancesheet?formType=" & #"FormTypes" & "&filingOrder=" & order, [Headers=[#"Ocp-Apim-Subscription-Key" = "redacted"]])),
    #"Converted to Table" = Record.ToTable(Source),
    #"Transposed Table" = Table.Transpose(#"Converted to Table"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table")
in
    #"Promoted Headers"
in
    Source

What I have done is to change it from your parameters in your Source line which might work?

 

    Source = Json.Document(Web.Contents("https://services.last10k.com/v1/company/" & #"ticker" & "/balancesheet?formType=" & #"FormTypes" & "&filingOrder=" & order, [Headers=[#"Ocp-Apim-Subscription-Key" = "redacted"]])),

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi otravers

 

Try this code:

= (ticker as text) as table =>
let
FormTypes = "10-Q",
order = "10-K", 

    Source = Json.Document(Web.Contents("https://services.last10k.com/v1/company/" & ticker & "/balancesheet?formType=" & FormTypes & "&filingOrder=" & order, [Headers=[#"Ocp-Apim-Subscription-Key" = "redacted"]])),
    #"Converted to Table" = Record.ToTable(Source),
    #"Transposed Table" = Table.Transpose(#"Converted to Table"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table")
in
    #"Promoted Headers"

I couldn't test it properly, as I don't have permission for this site.

 

Hp Pfister, order is a separate variable. What you're doing just hardcodes "10-Q" as the value for FormTypes, while what I'm looking for is a way to restrict input for FormTypes to its two valid values, 10-Q and 10-K.

 

smoupre, thanks but it looks too complicated for my purposes. I'll live with M's limitations 🙂

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals
Greg_Deckler
Super User
Super User

I do not believe that is a proper use case for parameters. I think you would be better off just coding it into your fucntion, something like:

 

values = {"10-Q", "10-K"}

And then just validating against that list.

 

For more on parameter use cases, I would refere to this excellent series of blog posts:

http://biinsight.com/power-bi-desktop-query-parameters-part-1/



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

OK, I did some more reading on function syntax but didn't find how to "just code" the acceptable values into the function using an array as you suggested. May I ask where you'd put it in the following code?

 

let
    Source = (ticker as text, FormTypes as text, order as text) as table =>
let
    Source = Json.Document(Web.Contents("https://services.last10k.com/v1/company/" & ticker & "/balancesheet?formType=" & FormTypes & "&filingOrder=" & order, [Headers=[#"Ocp-Apim-Subscription-Key" = "redacted"]])),
    #"Converted to Table" = Record.ToTable(Source),
    #"Transposed Table" = Table.Transpose(#"Converted to Table"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table")
in
    #"Promoted Headers"
in
    Source
------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

Hi @otravers

 

I think that you can put your variable as part of your function in your code below.

 

let
    Source = (ticker as text, FormTypes as text, order as text) as table =>
let
    Source = Json.Document(Web.Contents("https://services.last10k.com/v1/company/" & #"ticker" & "/balancesheet?formType=" & #"FormTypes" & "&filingOrder=" & order, [Headers=[#"Ocp-Apim-Subscription-Key" = "redacted"]])),
    #"Converted to Table" = Record.ToTable(Source),
    #"Transposed Table" = Table.Transpose(#"Converted to Table"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table")
in
    #"Promoted Headers"
in
    Source

What I have done is to change it from your parameters in your Source line which might work?

 

    Source = Json.Document(Web.Contents("https://services.last10k.com/v1/company/" & #"ticker" & "/balancesheet?formType=" & #"FormTypes" & "&filingOrder=" & order, [Headers=[#"Ocp-Apim-Subscription-Key" = "redacted"]])),

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Here is an example:

 

https://community.powerbi.com/t5/Community-Blog/Using-Recursion-to-Solve-Hex-to-Decimal-Conversion/b...

 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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