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
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
Good Morning techies, thank you very much, learnt a lot from this. Iam not used to define 'Inline'-Definition of functionalities, need to check on this on my own.