Forum Discussion
Correct Use of Text.Contains in Combination with List.Contains??
- 1 year ago
Hi thomasreick pls try this custom column
= if List.AnyTrue(List.Transform({"Gloves", "Vest", "Shorts"},
(x) => Text.Contains([item], x, Comparer.OrdinalIgnoreCase)))
then "Clothes"
else "Other" - 1 year ago
That's a well-known "feature" aka bug. The column statistics are cached and remember prior errors. Switch them off and on again to reset.
- 1 year ago
Hi thomasreick please check this, in the power query, on the advanced editor
let
CategoryMappings = [
Clothes = {"Cap", "Sleeve", "Gloves", "Vest", "Shorts", "Socks"},
Bikes = {"Mountain-", "Road-", "Race-", "Touring-"},
Accessories = {"Cage", "Dissolver", "Stand", "Rack", "Helmet", "Bottle", "Fender"},
SpareParts = {"Tire", "Patches"},
Nutrition = {}
],
GetCategory = (item as text) as text =>
let
Category = List.First(
List.Select(
Record.FieldNames(CategoryMappings),
each List.AnyTrue(
List.Transform(Record.Field(CategoryMappings, _),
(x) => Text.Contains(item, x, Comparer.OrdinalIgnoreCase))
)
)
)
in
if Category = null then "Nutrition" else Category,
AddedProductCategories_techies = Table.AddColumn(#"Changed Type1", "techies", each GetCategory([Item]), type text)in
AddedProductCategories_techies
The error message is because of your syntax. [Item] as written refers to the contents of a field or record. But in your code it is out of context.
In the Code below, I use Item to refer to a named variable that contains the text string being tested.
I think you want something like:
CategorizeItem = if List.AnyTrue(List.Accumulate(
{"Gloves","Vest","Shorts"},
{},
(s,c)=> s & {Text.Contains(Item,c,Comparer.OrdinalIgnoreCase)}))
then "Clothes"
else "Other"
Hi ronrsnfld,
thx for your Input. but the result ahs 100% Error although no rows are shown with 'Error' inside.
After Renaming the column Quality Column-Statistic went to green without Error. Will check the other approaches accordingly...
- lbendlin1 year ago
Super User
That's a well-known "feature" aka bug. The column statistics are cached and remember prior errors. Switch them off and on again to reset.