Forum Discussion

jduffey's avatar
jduffey
New Member
1 year ago
Solved

Inserting conditional column - compound conditions

Hi friends - 

What I'm looking to do is fairly straightforward.  I want to insert a conditional column in my PowerBI query.  Here are the conditions:

1. If Column [Medical] reads "Clear" AND if Column [Background] reads "Cleared" AND if column Contingencies Call reads "Completed"; OR

2. If Column [IHA] reads "IHA Approved",

I want the conditional column to read "Yes"

 

If condition 1 or condition 2 is not met, I want the conditional column to read No.

 

I am a beginner at DAX query and can't seem to get the formula right.  Is there anyone who can help me out with creating the correct formula?

 

Thank you!

  • Hi,

    I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

    Please check the below picture and the attached pbix file.

    It is for creating a calculated column.

     

     

     

    expected result CC = 
    IF (
        OR (
            AND ( data[medical] = "clear", data[background] = "cleared" ),
            data[IHA] = "approved"
        ),
        "Yes"
    )
    
  • jduffey add a new custom column in PQ with the following M code, change column name as per your table, and column names are case sensitive in PQ so make sure you are using the same column name.

     

    if ([Medical] = "Clear" and [Background] = "Cleared" and [Contingencies Call] = "Completed") or ([IHA] = "IHA Approvaed") then "Yes" else "No"
  • jduffey Jihwan_Kim solution is awesome but if possible I would avoid adding column in DAX, and add custom column as upstream possible.

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi,Jihwan_Kim and parry2k ,thanks for your concern about this issue.

    Your answers are excellent!
    Hello,jduffey .
    Has your problem been solved? If your problem has been solved, please mark the suggestion to solve the problem as a solution!
    Jihwan_Kim and parry2k provide both DAX and M code solutions respectively. The methods provided by them are valid. You can create calculated columns by using if function. In the calculated column, you determine the data of the column and return the corresponding state.

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Carson Jian

     

4 Replies

  • Hi,

    I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

    Please check the below picture and the attached pbix file.

    It is for creating a calculated column.

     

     

     

    expected result CC = 
    IF (
        OR (
            AND ( data[medical] = "clear", data[background] = "cleared" ),
            data[IHA] = "approved"
        ),
        "Yes"
    )
    
  • jduffey Jihwan_Kim solution is awesome but if possible I would avoid adding column in DAX, and add custom column as upstream possible.

  • jduffey add a new custom column in PQ with the following M code, change column name as per your table, and column names are case sensitive in PQ so make sure you are using the same column name.

     

    if ([Medical] = "Clear" and [Background] = "Cleared" and [Contingencies Call] = "Completed") or ([IHA] = "IHA Approvaed") then "Yes" else "No"
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,Jihwan_Kim and parry2k ,thanks for your concern about this issue.

    Your answers are excellent!
    Hello,jduffey .
    Has your problem been solved? If your problem has been solved, please mark the suggestion to solve the problem as a solution!
    Jihwan_Kim and parry2k provide both DAX and M code solutions respectively. The methods provided by them are valid. You can create calculated columns by using if function. In the calculated column, you determine the data of the column and return the corresponding state.

    I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
    Best Regards,
    Carson Jian