Forum Discussion
Strange Filter Situation Power Query
- 4 years ago
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZVNagMxDIWvMgxdmlqS/9dd9wQhi1AKDYSkpFnk+FWaGSPFbsHNKgp8z3rys7LZzDib+WV3eT9/7g+H3Zkr8BaiJSC8F+jWYnqalg+ZWOgZ4PbjvDWLzOntdDo+QiMKr6fLxzh//eGpNUKW4VWGhKtVBpNBSrILUj4kMyCw2hjC7y7cDd8dL/sv/oJgqTKIFrCdwzRlAKngpUKxFWExDB2+aDy0Y4wWcrXBRWlsBOOTlyqxpyKOFzBlkyLIEaYWduJULrAzCDSeouwh93ogL5w4aGW8geikTOlaiUKGOjLBRFS5KCpYCvobRJAX6mwdYrDNFNCAvk1ECbP3LOiHNGBLk6TZdR1e6s6Ou9e8SjMfrcLYz7LiVZaTpZqBLHr53Xwny7zbqu1bkXtBSjpI2Ekzdx/k027cUDElRnWR8XG34H8UxHLB7nsS2HXhkpwjiZt3thljuxKw85L4aKrdc5Ga28gmOLWgsfOSeLE78a6p0w2ZuuAmoVPnKKkhiXWQYwLLnw20XmQmQYZdrMkYvPqzAGVFQiMKq5Mhno1svwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Insect ID" = _t, #"Insect Description" = _t, Start = _t, Finish = _t, #"Insect Value" = _t, #"Want to Keep this Row" = _t]), #"Added Custom" = Table.AddColumn(Source, "Single", each let s=Table.SelectRows(Source,(k)=>[Insect ID]=k[Insect ID]) in Table.RowCount(s)=1 and s[Insect Description]{0}="Caterpillar"), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Insect Description] <> "Cocoon" and [Finish] <> " " and ([Insect Description] <> "Caterpillar" or [Single] = true)) in #"Filtered Rows"How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZVNagMxDIWvMgxdmlqS/9dd9wQhi1AKDYSkpFnk+FWaGSPFbsHNKgp8z3rys7LZzDib+WV3eT9/7g+H3Zkr8BaiJSC8F+jWYnqalg+ZWOgZ4PbjvDWLzOntdDo+QiMKr6fLxzh//eGpNUKW4VWGhKtVBpNBSrILUj4kMyCw2hjC7y7cDd8dL/sv/oJgqTKIFrCdwzRlAKngpUKxFWExDB2+aDy0Y4wWcrXBRWlsBOOTlyqxpyKOFzBlkyLIEaYWduJULrAzCDSeouwh93ogL5w4aGW8geikTOlaiUKGOjLBRFS5KCpYCvobRJAX6mwdYrDNFNCAvk1ECbP3LOiHNGBLk6TZdR1e6s6Ou9e8SjMfrcLYz7LiVZaTpZqBLHr53Xwny7zbqu1bkXtBSjpI2Ekzdx/k027cUDElRnWR8XG34H8UxHLB7nsS2HXhkpwjiZt3thljuxKw85L4aKrdc5Ga28gmOLWgsfOSeLE78a6p0w2ZuuAmoVPnKKkhiXWQYwLLnw20XmQmQYZdrMkYvPqzAGVFQiMKq5Mhno1svwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Insect ID" = _t, #"Insect Description" = _t, Start = _t, Finish = _t, #"Insect Value" = _t, #"Want to Keep this Row" = _t]),
#"Added Custom" = Table.AddColumn(Source, "Single", each let s=Table.SelectRows(Source,(k)=>[Insect ID]=k[Insect ID]) in Table.RowCount(s)=1 and s[Insect Description]{0}="Caterpillar"),
#"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Insect Description] <> "Cocoon" and [Finish] <> " " and ([Insect Description] <> "Caterpillar" or [Single] = true))
in
#"Filtered Rows"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".
- Anonymous4 years agoNot applicable
Thank you so much for your fast response! In my case, I am using power query with an Excel workbook and it looks like you are referencing a JSON object. Would I add your code like below if I wanted to use it with my Excel table?
let Source = Table.FromRows( Excel.CurrentWorkbook(){[Name="Table1"]}[Content], let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Insect ID" = _t, #"Insect Description" = _t, Start = _t, Finish = _t, #"Insect Value" = _t, #"Want to Keep this Row" = _t] ), #"Added Custom" = Table.AddColumn( Source, "Single", each let s=Table.SelectRows( Source, (k)=>[Insect ID]=k[Insect ID] ) in Table.RowCount(s)=1 and s[Insect Description]{0}="Caterpillar" ), #"Filtered Rows" = Table.SelectRows( #"Added Custom", each [Insect Description] <> "Cocoon" and [Finish] <> " " and ([Insect Description] <> "Caterpillar" or [Single] = true ) ) in #"Filtered Rows"I did notice that I got the below error when I used this code. What would you recommend?
"Expression.Error: We cannot convert a value of type Table to type List.
Details:
Value=[Table]
Type=[Type]"When I asked it to show me the error, it showed me the Source step.
- lbendlin4 years agoSuper User
Use your excel table as the source and then manually add the other two transforms.