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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
thejayo
New Member

Converting Table Column with numbers to List using Table.ToList

Hi everyone,

 

I'm working on a query which applies a calculation to each column in a table. I have included a simplified snipped of the code with which I'm struggling below.

 

let
    n = 1, // this will change based on another variable
    
    dataTable = #table({"X","Column A","Column B"},{{100,1,2},{200,3,4}}),

    columnName = Table.ColumnNames(dataTable){n},

        myFunction = (list1 as list, list2 as list) =>
            let
                product = List.Sum(list1) * List.Sum(list2)
            in
                product,

    result = myFunction(dataTable[X], Table.ToList(Table.SelectColumns(dataTable, columnName)))
in
    result

 

Basically, what I'm trying to do is multiply column A and column B with column X and then build a new table with the results. In reality there will be hundreds of columns so I want to reference these columns dynamically. The code that changes "n" and builds the new table with the results is working already.

 

The only issue I'm having is with calling myFunction dynamially.

This works as intended but is obviously not dynamic

result = myFunction(dataTable[X], dataTable[A])

This does not work and I get the error "We cannot convert the value 1 to type Text"

result = myFunction(dataTable[X], Table.ToList(Table.SelectColumns(dataTable, columnName)))

 

I would appreciate any suggestions how to solve this. Thank you!

1 ACCEPTED SOLUTION
thejayo
New Member

Managed to sort this.

For future reference this did the trick:

result = myFunction(dataTable[x], Table.Column(dataTable, columnName))

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Try changing

 

columnName = Table.ColumnNames(dataTable){n}

to

 

Table.ColumnNames(dataTable{n})

--Nate

 

thejayo
New Member

Managed to sort this.

For future reference this did the trick:

result = myFunction(dataTable[x], Table.Column(dataTable, columnName))

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.