Forum Discussion
[Expression.Error] We cannot convert a value of type List to type Record.
Hello Anonymous
this code is ok. The problem is caused by the function getPage, that somehow for some transformation needs a record, but it gets a list instead.
BR
Jimmy
Jimmy
Thanks for the help, but I am not sure what that means - would viewing the code for the getPage be of use?
- Jimmy8015 years ago
Community Champion
Hello Anonymous
this could get nasty and without nowing the datasource (data elaborated by the getpage-function) is almost inpossible to help. If your Json-data however comes in formated in a way data for some field you have a record and list, you could make a Table.TransformColumns with Table.ExpandTableColumn instead of usind only Table.ExpandRecordColumm. Here a practicable example
let Source = Json.Document("[{""a"":2},[""a;2""]]#(cr)#(lf)"), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), TransformColumns = Table.TransformColumns ( #"Converted to Table", { { "Column1", each if Value.Is(_, type list) then Table.FromRecords({Record.FromList({List.Transform(_, each Text.Split(_,";")){0}{1}},{List.Transform(_, each Text.Split(_,";")){0}{0}})},null,MissingField.Error) else if Value.Is(_, type record) then Table.FromRecords({_},null,MissingField.Error) else null } } ), #"Expanded Column1" = Table.ExpandTableColumn(TransformColumns, "Column1", {"a"}, {"a"}) in #"Expanded Column1"Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy - edhans5 years ago
Community Champion
Well, that code is expecting a record via the Table.FromRecords function, and if your data is returning a list it will fail. Perhaps ask the OP of that post since you and that person seem to be accessing the same data. Perhaps Jimmy801 has an idea beyond the try/otherwise construct that will fail, but even though I can convert a list to a table, I cannot do it blindly not knowing what is in the list and how to handle the resulting data, and to get to mirror how the records look, also being unable to see them.
- edhans5 years ago
Community Champion
Absolutely Anonymous- always good to give kudos to posts that are helpful. 👍😁
sorry couldn't be more help. It is difficult to troubleshoot shoot errors on a forum and even more so when it is the result of nested tables, lists, and records.
- Jimmy8015 years ago
Community Champion
Hello Anonymous
in the following step you can see that some custom function is applied to read the data. This function creates your output, and probably it's there where the error is caused
BR
Jimmy
- edhans5 years ago
Community Champion
What is getPage doing Anonymous ?
The function itself may be fine assuming everything coming in is a record. But if it is coming in as a List then the function needs to be rewritten.However, given that not everything is an error, only 758 records of your total data set are, then it suggests that the field in question is sometimes a list, and sometimes a record. getPage would need to be rewritten to handle that. The fastest way would be to adjust the getPage code to this:
try INSERT YOUR getPage CODE HERE otherwise nullSo if it is a record, getPage works, or adjust the code near the top as follows:
#"Invoked Custom Function" = Table.AddColumn(#"Changed Type", "Data", each getPage([Column1])),becomes
#"Invoked Custom Function" = Table.AddColumn(#"Changed Type", "Data", each try getPage([Column1]) otherwise null),That will simply drop the invalid data that getPage cannot handle. That may be the solution. It will certianly clear this error, but may drop needed data since anything on those 758 rows will not come through.
Without the source data to look at though it is very difficult to troubleshoot in a forum.
- Anonymous5 years agoNot applicable
Thanks in regards to where I am and the code source this is the resource I used
https://stackoverflow.com/questions/46904641/how-to-get-paginated-data-from-api-in-power-bi
- Anonymous5 years agoNot applicable
I must admit this is getting abit above me at the mo and I will need to go back and take on board all suggested here, I would like to say thanks to both for the help and guidance provided so what is the best way to the thanks to the both of you - click the kudos button on different posts?
- Anonymous5 years agoNot applicable
You are using a list as your parameter for the getpage() function [Column1]. You could probably just do Table.AddColumn(PriorStep, "Page", each [Column1])
- Anonymous5 years agoNot applicable
Hi thanks for the reply, is that in reference to line 6 #"Converted to Table" or line 7 #"Expanded Column1" - please?
- Icey5 years ago
Community Support
Hi Anonymous ,
Based on the current information, I cannot reproduce your issue. It is suggest to provide more information to help me better understand the issue you are experiencing.
Best Regards,
Icey