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
coolshib
Helper III
Helper III

Need help on Search and replace value in power query

Hello Everyone,
i am looking for custom function which would check If contains "Dr" or "Cr" and replace the same will nothing and also multiplies with 1 if the word is "Dr" and multiplies with -1 if the word is "Cr".
For example, following is the sample table:

268740.00 Cr
1652420.00 Cr
22228.00 Dr

I am looking for result as follows:​

-268740​
-1652420​
22228​

Hope i explained my query properly. Thank is advance.
Best Regards,
 
1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @coolshib 

 

If you only have Cr or Dr in the column, you can use if statement

Vera_33_0-1627362631675.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjKzMDcx0DMwUHAuUorViVYyNDM1MjFCFjECAgsQ3wXIjwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
if Text.Contains([Column1],"Cr") 
then Number.From(Text.Select([Column1],{"0".."9"}))*-1 
else Number.From( Text.Select([Column1],{"0".."9"})), type number)
in
    #"Added Custom"

 

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

Hi @coolshib 

 

If you only have Cr or Dr in the column, you can use if statement

Vera_33_0-1627362631675.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjKzMDcx0DMwUHAuUorViVYyNDM1MjFCFjECAgsQ3wXIjwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each 
if Text.Contains([Column1],"Cr") 
then Number.From(Text.Select([Column1],{"0".."9"}))*-1 
else Number.From( Text.Select([Column1],{"0".."9"})), type number)
in
    #"Added Custom"

 

Thank you so much @Vera_33 !! This is Exactly  what i wanted..

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.