cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
freelensia Regular Visitor
Regular Visitor

Passing a list or array to a function

Hi,

 

I have a simple function that evaluates an Excel's Named Range to get its value like this:

(RangeValue as text) =>
let
    RangeValue = Excel.CurrentWorkbook(){[Name=RangeName]}[Content]{0}[Column1]
in
    RangeValue

To call this I simply do

RangeValue("SomeExcelNamedRange")

However, this will evaluate only individual named ranges at a time. What if I want to evaluate 3, 4, or any other number named ranges from Excel? I would call the new function like this:

RangeValues({"Name1", "Name2", ... "NameN"})

 

Could you help me write this new function?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Passing a list or array to a function

Here is an example

https://www.dropbox.com/s/r2ha4qe9513ft08/functions.xlsx?dl=1



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

4 REPLIES 4
Highlighted

Re: Passing a list or array to a function

What you have written as the pseudo code is one function with 3 parameters. You could execute the same function that takes 1 parameter 3 times instead. In power query, create. List of ranges. {“rg1”,”rg2”} etc. Convert to a table, Then insert column, invoke custom function and pass the column values to the function. Then combine



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
freelensia Regular Visitor
Regular Visitor

Re: Passing a list or array to a function

Sorry could you show me the code to do that?

I am not sure what your method does, but how would I invoke this new function?
The simplicity that I seek is that I can easily type in one line the items in my list and the desired macro would execute them, without having to create new queries or tables.

Re: Passing a list or array to a function

Here is an example

https://www.dropbox.com/s/r2ha4qe9513ft08/functions.xlsx?dl=1



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

View solution in original post

Community Support Team
Community Support Team

Re: Passing a list or array to a function

Hi @freelensia ,

Have you solved your problem?

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

If you still need help, please feel free to ask.

Best  Regards,

Cherry

 

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

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors