Forum Discussion
Receiving Error After Unpivoting Columns in Power Query
I'm trying to alphabetize a column of email addresses, separated by a semi colon. I found if I added an index column, split by delimiter, unpivoted the columns, sorted the rows, grouped the rows, and then add a custom column combining the data, I was able to achieve this. However, coming back to it today, it no longer works and is throwing a DataFormat.Error: Invalid cell value '#NAME?' error.
After messing around with adding different steps to see if I kept getting the error, I noticed that no matter what I added after the Unpivoted Columns step, I will get this error. I did some research and it seemed that it was a type error so I switched all types by using "Detect Data Type". This still did not work. I also tried replacing all the nulls from splitting by delimiter and all blank cells with "Null" (not sure if there was any but wanted to be thorough). I turned on "Column quality" to see where the error was coming from and I'm getting 100% valid on all columns
My code:
let
Source = Excel.CurrentWorkbook(){[Name="ACR"]}[Content],
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Type] = "Assets" or [Type] = "Links")),
#"Replaced Value" = Table.ReplaceValue(#"Filtered Rows"," ","",Replacer.ReplaceText,{"ContentOwner"}),
#"Added Index" = Table.AddIndexColumn(#"Replaced Value", "Index", 1, 1, Int64.Type),
#"Split Column by Delimiter" = Table.SplitColumn(#"Added Index", "ContentOwner", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"ContentOwner.1", "ContentOwner.2", "ContentOwner.3", "ContentOwner.4", "ContentOwner.5"}),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"SiteCollection", type text}, {"Site", type text}, {"ContentId", Int64.Type}, {"ContentOwner.1", type text}, {"ContentOwner.2", type text}, {"ContentOwner.3", type text}, {"ContentOwner.4", type text}, {"ContentOwner.5", type text}, {"Title", type text}, {"Index", Int64.Type}}),
#"Replaced Value1" = Table.ReplaceValue(#"Changed Type",null,"Null",Replacer.ReplaceValue,{"ContentOwner.2", "ContentOwner.3", "ContentOwner.4", "ContentOwner.5"}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Replaced Value1", {"SiteCollection", "Site", "ContentId", "Title", "Index"}, "Attribute", "Value"),
#"Sorted Rows" = Table.Buffer(Table.Sort(#"Unpivoted Columns",{{"Index", Order.Descending}, {"Content Owner", Order.Ascending}}))
in
#"Sorted Rows"
Note: I tried to moving the Changed Type step to after the Unpivoted Columns step and I still receive the same error.
I used Table.Buffer here because the grouping did not maintain the sort I specified on this step. Once I added Table.Buffer, it did. I removed it in trying to solve this problem and I still get the error.
View when on the Unpivoted Columns step:
Due to the nature of the data, I cannot share the file so if there is any clarification I can provide, please let me know.
Try below with better error handling:
let Source = Excel.CurrentWorkbook(){[Name="ACR"]}[Content], #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]), #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Type] = "Assets" or [Type] = "Links")), #"Replaced Value" = Table.ReplaceValue(#"Filtered Rows"," ","",Replacer.ReplaceText,{"ContentOwner"}), #"Added Index" = Table.AddIndexColumn(#"Replaced Value", "Index", 1, 1, Int64.Type), #"Split Column by Delimiter" = Table.SplitColumn(#"Added Index", "ContentOwner", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"ContentOwner.1", "ContentOwner.2", "ContentOwner.3", "ContentOwner.4", "ContentOwner.5"}), #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"SiteCollection", type text}, {"Site", type text}, {"ContentId", Int64.Type}, {"ContentOwner.1", type text}, {"ContentOwner.2", type text}, {"ContentOwner.3", type text}, {"ContentOwner.4", type text}, {"ContentOwner.5", type text}, {"Title", type text}, {"Index", Int64.Type}}), #"Replaced Value1" = Table.ReplaceValue(#"Changed Type",null,"Null",Replacer.ReplaceValue,{"ContentOwner.2", "ContentOwner.3", "ContentOwner.4", "ContentOwner.5"}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Replaced Value1", {"SiteCollection", "Site", "ContentId", "Title", "Index"}, "Attribute", "Value"), #"Removed Errors" = Table.SelectRows(#"Unpivoted Columns", each not Text.Contains([Value], "#NAME?")), #"Sorted Rows" = Table.Buffer(Table.Sort(#"Removed Errors",{{"Index", Order.Descending}, {"Value", Order.Ascending}})) in #"Sorted Rows"
- renee_crozierBrass Contributor
I still got an error with using your code but when I clicked "Remove Errors" on the Index, Attribute, and Value columns, the error got cleared. Is there a way to see where the error was? I'm now unsure how accurate my information is if I can't see what was removed.
renee_crozier , I'd start from Promote Headers step. At left bottom of Power Query Editor window set "Column profiling based on entire data set". On ribbon -> View enable Column Quality.
Check for which columns number of errors is not 0%. Select these columns, on ribbon Home->Keep Rows->Keep errors. Most probably you may identify the source of errors here.