Forum Discussion

freelensia's avatar
freelensia
Advocate II
7 years ago
Solved

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

4 Replies

  • MattAllington's avatar
    MattAllington
    Community Champion

    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