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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Create new column in power query using IF & ISERROR LOGIC

IF($G2="In",IF(ISERROR(FIND(I$1,$H2)),0,1),0)

Aboce is the excell formaule which created new column in excell 
need power query code to created same logic 

 

 

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

to exactly reproduce your desired result in Power Query you don't need an error handling for a find-function because Text.Contains will never handle back an error. So you just need a nested if-function for this. Here the formula

if [G]="In" then if Text.Contains([I],[H]) then 1 else 0 else 0

Here a complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sxT0lFKBOIkpVidaCX/0hIYvyg1MUUpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [G = _t, H = _t, I = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"G", type text}, {"H", type text}, {"I", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [G]="In" then if Text.Contains([I],[H]) then 1 else 0 else 0)
in
    #"Added Custom"

Jimmy801_0-1613119369026.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

to exactly reproduce your desired result in Power Query you don't need an error handling for a find-function because Text.Contains will never handle back an error. So you just need a nested if-function for this. Here the formula

if [G]="In" then if Text.Contains([I],[H]) then 1 else 0 else 0

Here a complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sxT0lFKBOIkpVidaCX/0hIYvyg1MUUpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [G = _t, H = _t, I = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"G", type text}, {"H", type text}, {"I", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [G]="In" then if Text.Contains([I],[H]) then 1 else 0 else 0)
in
    #"Added Custom"

Jimmy801_0-1613119369026.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

Anonymous
Not applicable

Hello @Jimmy801  firstly Thanks for the reply it worked. just chaged [H] to "H" as this is a constant one and it worked .

 

Below is the code which worked for me as per my requirement.

 

 

if [G]="In" then if Text.Contains([I],"H") then 1 else 0 else 0

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors