Forum Discussion
Error: We Cannot Convert a value of Type List to Type Text
Hi BA_Pete,
I am needing to filter a table to only contain rows that are the max within the count column. Therefore, I am trying to retrive the max value within the count column and use it as a variable (although I do not necessarily need to use it as a variable and could integrate in the filtering step).
To provide further context of what I am trying to achieve:
I have a table of records that have I need to expand and unpivot (refer to image below)
In this example there are only 2 revisions (A and B) but this could be any number and the field names within these records are all unique across revisions. Hence, I have implemented dynamic expansion of these records. To do this, I have stored the field names from the records as lists in a separate column.
Then I have combined these lists in the fields column
Expanded the records table using this combined list
Unpivoted these columns
And finally obtained the count from the 'Value' column
This is where I want to filter all rows to only contain those that are equal to the max within the count column (i.e. 11 in this specific case.
The m-code can be seen below (with the api link removed for personal reasons)
let
Source = Json.Document(Web.Contents("API_Link" & Teamspace & "/" & #"Model ID" & "/revisions.json?key=" & #"API Key")),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"_id", "author", "desc", "tag", "timestamp", "name", "branch", "fileType"}, {"_id", "author", "desc", "tag", "timestamp", "name", "branch", "fileType"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Column1",{"_id", "author", "desc", "timestamp", "name", "branch", "fileType"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"tag", "Revision Name"}}),
#"Invoked Custom Function" = Table.AddColumn(#"Renamed Columns", "Data", each #"Retrieve Clean Unity_ID"([Revision Name])),
#"Expanded Data" = Table.ExpandTableColumn(#"Invoked Custom Function", "Data", {"Value"}, {"Value"}),
#"Added Custom" = Table.AddColumn(#"Expanded Data", "Custom", each Record.Field([Value],"idToPath")),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Added Custom", {"Custom"}),
#"Removed Columns1" = Table.RemoveColumns(#"Removed Errors",{"Value"}),
#"Added Custom4" = Table.AddColumn(#"Removed Columns1", "Fields", each Record.FieldNames([Custom])),
List_Example = List.Buffer(List.Combine(#"Added Custom4"[Fields])),
#"Expanded DetailsRecord" = Table.ExpandRecordColumn(#"Added Custom4", "Custom", List_Example, List_Example),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Expanded DetailsRecord", {"Revision Name"}, "Attribute", "Value"),
#"Added Custom1" = Table.AddColumn(#"Unpivoted Other Columns", "Count", each List.Count(Text.SplitAny([Value],"_"))),
#"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Count", Int64.Type}}),
Max_num = List.Max(#"Changed Type"[Count]),
#"Added Custom2" = Table.AddColumn(#"Changed Type", "Max Number", each Max_num),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom", each if [Count] = [Max Number] then [Attribute] else null),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom3",{"Custom", "Revision Name"}),
#"Renamed Columns1" = Table.RenameColumns(#"Removed Other Columns",{{"Custom", "Unity_id"}}),
#"Filtered Rows" = Table.SelectRows(#"Renamed Columns1", each ([Unity_id] <> null))
in
#"Filtered Rows"
Sorry for the long explanation and thank you for your help!