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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Class66Loco
Frequent Visitor

if [column1] = "ABC" and [column2] = "123" then 1 else 0

Hello,

I'm trying to create a custom column that returns 1 or 0 depending on if specific values of two columns are met.

 

My current code below is only returning 0 (FALSE):
= if [Status]= "Responded" and [WithinSLA] = "TRUE" then 1 else 0

 

I'd like to return 1 (TRUE) if there's "Responded" in the Status column and if "TRUE" is in the WithinSLA column.

Thanks for any help.

1 ACCEPTED SOLUTION
Alex87
Solution Supplier
Solution Supplier

Hello,

Best practice is to add the new column inside power query (copy paste this code inside a new blank query/ advanced editor): 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkotLsjPS0lNUdJRCgkKdVWK1YlWCkjNS8nMSwcKuTn6BEPEkBVCRWMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Status = _t, WithinSLA = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status", type text}, {"WithinSLA", type logical}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Status] = "Responded" and [WithinSLA] = true then 1 else 0, type number)
in
    #"Added Custom"

 

 

but if you prefer a DAX calculated column, this should do the work:

 

Custom2 = 
IF(MyTable[Status] = "Responded" && MyTable[WithinSLA] = TRUE(), 1, 0)

 

If it answers your query, please mark my pos as the solution. Thanks!

 

Best regards,

Alex

 

View solution in original post

1 REPLY 1
Alex87
Solution Supplier
Solution Supplier

Hello,

Best practice is to add the new column inside power query (copy paste this code inside a new blank query/ advanced editor): 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkotLsjPS0lNUdJRCgkKdVWK1YlWCkjNS8nMSwcKuTn6BEPEkBVCRWMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Status = _t, WithinSLA = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status", type text}, {"WithinSLA", type logical}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Status] = "Responded" and [WithinSLA] = true then 1 else 0, type number)
in
    #"Added Custom"

 

 

but if you prefer a DAX calculated column, this should do the work:

 

Custom2 = 
IF(MyTable[Status] = "Responded" && MyTable[WithinSLA] = TRUE(), 1, 0)

 

If it answers your query, please mark my pos as the solution. Thanks!

 

Best regards,

Alex

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.