Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Tmk123
Helper II
Helper II

Table.ReplaceValue help

Hello,

 

I am looking over a personal budget.  I want to update the column Category to "Alcohol" based on a keyword in the description column (case insensitive).  So...if the description contains "wine" or "liquor" change the category to "Alcohol"

 

I know creating a conditional column is an option but wanted to practice M-queries in power query. 

 

AmountTransaction DateDescriptionCategoryCategory (#Update)
$20.0001/01/2023

Total Wine and More

MerchandiseAlcohol
$10.0002/01/2023

TOTAL WINE AND MORE

MerchandiseAlcohol
$35.0003/01/2023HOMESENSE #02567MerchandiseMerchandise
$15.0005/01/2023ABC Liquor StoreMerchandiseAlcohol

 

Both columns are Text columns, if important.

Tmk123_1-1698494541673.png

 

The following is not working as intended.  It appears what I wrote below requires the description to be an exact match for the entire cell.  I want it to search each record in the category column for a single word, regardless of the case.

 

= Table.ReplaceValue(
#"Replaced Value1",
each [Category],
each if
Text.Contains([Description], "liquor", Comparer.OrdinalIgnoreCase) and
Text.Contains([Description], "wine", Comparer.OrdinalIgnoreCase)
then "Groceries"
else [Category],
Replacer.ReplaceText,
{"Category"})

 

Thanks for your help!!!

1 ACCEPTED SOLUTION
ThxAlot
Super User
Super User

= Table.ReplaceValue(Source, each [Category], each if List.Contains({"wine","liquor"},[Description],(x,y)=>Text.Contains(y,x,Comparer.OrdinalIgnoreCase)) then "Alcohol" else [Category], Replacer.ReplaceText, {"Category"})

ThxAlot_0-1698506464240.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

2 REPLIES 2
Tmk123
Helper II
Helper II

Thanks a lot, ThxAlot .  That worked!

ThxAlot
Super User
Super User

= Table.ReplaceValue(Source, each [Category], each if List.Contains({"wine","liquor"},[Description],(x,y)=>Text.Contains(y,x,Comparer.OrdinalIgnoreCase)) then "Alcohol" else [Category], Replacer.ReplaceText, {"Category"})

ThxAlot_0-1698506464240.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.