Forum Discussion
Cannot convert a value of type Table to type List - data export from a sharepoint
The error you're encountering, "Expression.Error: We cannot convert a value of type Table to type List," usually occurs when there's a mismatch between the expected data types in a function. In your code, this error is likely happening in the `Table.TransformColumns` function calls, where you are attempting to use the `Table.ToRows` output (which is a list of lists) as a transformation specification in `Table.TransformColumns`. `Table.TransformColumns` expects a list of column transformation specifications, typically provided as a list of tuples.
To correct this error, we need to adjust the way you're creating the `UserMultiChanges`, `UserChanges`, `LookupChanges`, etc., so that they're in the format expected by `Table.TransformColumns`. Each of these variables should be a list of tuples, where each tuple consists of the column name to be transformed and the transformation function to apply.
Here's how you can modify your code:
1. Change the `Table.ToRows` to `Table.ToRecords` in the transformations for `UserMultiChanges`, `UserChanges`, `LookupChanges`, and so on. This change is necessary because `Table.TransformColumns` expects a list of records (tuples) specifying the column name and the transformation function.
2. Make sure that the transformation function is correctly defined. Currently, it seems like you are trying to pass column names to the transformation functions which may not be the correct approach depending on your data structure and what you're trying to achieve.
I'll modify the first few transformations as an example:
UserMultiTransforms = Table.AddColumn(UserMultiTypeRows, "UserMultiTransform", each (name) =>
if (name <> "") then text.Combine(Table.Column(Table.FromList(name, Record.FieldValues, UserMultiFieldNames), "title"), ", ") else null, Function.Type),
UserMultiChanges = Table.ToRecords(Table.SelectColumns(UserMultiTransforms, { "Name","UserMultiTransform"})),
ExpandedUserMulti = Table.TransformColumns(Navigation, UserMultiChanges),
UserTypeRows = Table.SelectRows(TableSchema, each [NativeTypeName] = "User"),
UserFieldNames = {"id", "title", "email", "sip", "picture", "jobTitle", "department"},
UserTransforms = Table.AddColumn(UserTypeRows, "UserTransform", each (name) =>
if (name <> "") then text.Combine(Table.Column(Table.FromList(name, Record.FieldValues, UserFieldNames), "title"), ", ") else null, Function.Type),
UserChanges = Table.ToRecords(Table.SelectColumns(UserTransforms, { "Name","UserTransform"})),
ExpandedUser = Table.TransformColumns(ExpandedUserMulti, UserChanges),
Apply similar changes to the other transformations in your code. Remember, the key is to provide `Table.TransformColumns` with a list of tuples where each tuple contains a column name and a corresponding transformation function.
Hello,
Thank you for your response. I'm not very well read in power query so trying to understand what you mean by 'Make sure that the transformation function is correctly defined'. This code is what Power BI did automatically for me when I exported from the sharepoint table.
When I replace Table.toRows to Table.toRecords for all my transformations, I instead get this error:
What does this mean?
- Neo_Mando2 years agoNew Member
I've exactly the same problem and still not found a solution, do you ?
- SimpleHuMan1 year agoNew Member
Hi Neo_Mando, I hope you found the solution to the problem.
My solution was to change UserMultiTransform script. Changes marked in bold below. I hope this helps.
UserMultiTransform = Table.AddColumn(UserMultiTypeRows, "UserMultiTransform", each(name) =>
if (name <> null) then @Text.Combine(Table.Column(Table.FromList(Table.ToRecords(name), Record.FieldValues, UserFieldNames), "title"), ", ") else null, Function.Type)