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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Hemendra3
New Member

undefined

I have a column say division # 61, 62, 92 and wanted to create a new column as [Rev. Description]

if [Div]= 62 and column [Description ] having text say "Abs" then convert as "Absolute" and "Doc"  as "Doctor"

if [Div]= 22 and column [Description ] having text say "Mon" then convert as "Monday" 

else [Description ] 

I wrote MQuery with contains (ignore case sensitive by "Comparer.OrdinalIgnoreCase") but my file stopped loading. when I deleted this step, it was back on track. how to mitigate this?

my exact query was as under :

 

= Table.AddColumn(
#"Prod Category",
"Product Category",
each
if [Division] = 62 and Text.Contains([Product Description], "petronas", Comparer.OrdinalIgnoreCase) then "Engine Oil"
else if [Division] = 62 and Text.Contains([Product Description], "Reniso", Comparer.OrdinalIgnoreCase) then "Reniso"
else if [Division] = 92 and Text.Contains([Product Description], "Compressor", Comparer.OrdinalIgnoreCase) then "RF Compressor"
else [Product Description],
type text

 

Thanks in avdance.

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @Hemendra3, another solution.

 

Add mnore replacements as list of lists in Replacements step.

Before

dufoq3_0-1755767647082.png

 

After

dufoq3_1-1755767662116.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjNU0lFyTCpWKM7PTVUoSa0oUfDNz1OK1QFKGQGlghNLk1KLFApSS4ry8xKLwRKWIIn8kgygOFAtWJNSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Division = _t, Description = _t]),
    Replacements = List.Buffer(
  { {"Abs", "Absolute"},
    {"Mon", "Monday"},
    {"Petronas", "Engine Oil"} }),
    ReplacedDescription = Table.TransformColumns(Source,{{"Description", each Text.Combine(List.ReplaceMatchingItems(Text.Split(_, " "), Replacements, Comparer.OrdinalIgnoreCase), " "), type text}})
in
    ReplacedDescription

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

6 REPLIES 6
v-aatheeque
Community Support
Community Support

Hi @Hemendra3 

Following up to see if the solution shared by @Shahid12523 @bhanu_gautam @dufoq3 helped with the Text.Contains logic in your M Query. Were you able to load the file successfully after applying the updated step to create the  column?

Hi @Hemendra3 

Just following up to check if the solution shared by @Shahid12523, @bhanu_gautam, and @dufoq3 helped with the Text.Contains logic in your M Query.

Were you able to load the file successfully after applying the updated step to create the column?

If we don’t hear back, we may close this thread in line with our community guidelines, but you’re always welcome to post a new query anytime.

Thank you for being part of the Microsoft Fabric Community!



Shahid12523
Community Champion
Community Champion

Your query hangs because Comparer.OrdinalIgnoreCase breaks query folding → Power Query scans all rows locally.

 

How to Fixes:

Filter [Division] first (reduce rows).

Use Text.Lower([Product Description]) + search lowercase terms (faster than Comparer.OrdinalIgnoreCase).

Best: move the logic into SQL (CASE WHEN).

 

Recommended: replace Comparer.OrdinalIgnoreCase with Text.Lower().

Shahed Shaikh
dufoq3
Super User
Super User

Hi @Hemendra3, another solution.

 

Add mnore replacements as list of lists in Replacements step.

Before

dufoq3_0-1755767647082.png

 

After

dufoq3_1-1755767662116.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjNU0lFyTCpWKM7PTVUoSa0oUfDNz1OK1QFKGQGlghNLk1KLFApSS4ry8xKLwRKWIIn8kgygOFAtWJNSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Division = _t, Description = _t]),
    Replacements = List.Buffer(
  { {"Abs", "Absolute"},
    {"Mon", "Monday"},
    {"Petronas", "Engine Oil"} }),
    ReplacedDescription = Table.TransformColumns(Source,{{"Description", each Text.Combine(List.ReplaceMatchingItems(Text.Split(_, " "), Replacements, Comparer.OrdinalIgnoreCase), " "), type text}})
in
    ReplacedDescription

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

bhanu_gautam
Super User
Super User

@Hemendra3 , Try using

 

let
Source = #"Prod Category",
AddRevDescription = Table.AddColumn(
Source,
"Rev. Description",
each if [Division] = 62 and Text.Contains([Description], "Abs", Comparer.OrdinalIgnoreCase) then "Absolute"
else if [Division] = 62 and Text.Contains([Description], "Doc", Comparer.OrdinalIgnoreCase) then "Doctor"
else if [Division] = 22 and Text.Contains([Description], "Mon", Comparer.OrdinalIgnoreCase) then "Monday"
else [Description],
type text
)
in
AddRevDescription




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @Hemendra3 

Just checking in to see if the solution shared by the @bhanu_gautam helped resolve your issue with the Text contians logic in M Query. Were you able to load your file successfully with the updated step for creating the [Rev. Description] column?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.