Forum Discussion

akito's avatar
akito
Frequent Visitor
4 years ago
Solved

IF with multiple condition (more than 3) + DAX formula help needed

Hi Masters,

 

I am pretty new in DAX as well as in Power BI. 

 

Please see below snapshots : Basically I am trying to mark/tag my projects with specific words based on their approval statuses. I have 3 types of approvals and if all have "Yes" I would like to write and tag that project as "F-R-W" whcih stands for "Finance - Risk  - Workstream". I am able to do this in excel table where I have one table. However now I am trying to do this in database where I have many tables with relationships. It is not only question around multiple AND conditon with IF, it is also how I can do this in  database where I have multiple tables . Please check snapshots and i hope you will understand what I am trying to do. 

 

Excel formula that I used to use:

In DAX  - what I am trying to do

Expected DAX outcome:

 

Regards,

Akito

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi akito ,

     

    Try this measure.

    Required Approvals = 
    VAR _finance_approvals =
        MAX ( 'Initiative Pending Approval'[Finance Approvals] )
    VAR _risk_approvals =
        MAX ( 'Initiative Pending Approval'[Risk Approvals] )
    VAR _workstream_approvals =
        MAX ( 'Initiative Pending Approval'[Workstream Approvals] )
    RETURN
        SWITCH (
            TRUE (),
            _finance_approvals = "Yes"
                && _risk_approvals = "Yes"
                && _workstream_approvals = "Yes", "F-R-W",
            _finance_approvals = "Yes"
                && _risk_approvals = "Yes"
                && _workstream_approvals = "", "F-R",
            _finance_approvals = "Yes"
                && _risk_approvals = ""
                && _workstream_approvals = "", "F"
        )

    Attached PBIX file for reference.

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi akito ,

     

    Try this measure.

    Required Approvals = 
    VAR _finance_approvals =
        MAX ( 'Initiative Pending Approval'[Finance Approvals] )
    VAR _risk_approvals =
        MAX ( 'Initiative Pending Approval'[Risk Approvals] )
    VAR _workstream_approvals =
        MAX ( 'Initiative Pending Approval'[Workstream Approvals] )
    RETURN
        SWITCH (
            TRUE (),
            _finance_approvals = "Yes"
                && _risk_approvals = "Yes"
                && _workstream_approvals = "Yes", "F-R-W",
            _finance_approvals = "Yes"
                && _risk_approvals = "Yes"
                && _workstream_approvals = "", "F-R",
            _finance_approvals = "Yes"
                && _risk_approvals = ""
                && _workstream_approvals = "", "F"
        )

    Attached PBIX file for reference.

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly -- How to provide sample data

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous hey nice one ..

      I am also working and struggling to get one of the IF logic conditions as below :

       

      Logic :

      if "Are there any changes between SOW Agreed Scope & Revised Scope?" is Yes and "Is the devaition between SOW Agreed scope and revised scope has major deviation?" is Yes --> Red

                    if "Is the CR raised?" is yes or No then keep it Red

                    if "Is the CR raised?" is yes and "Is the CR approved?" is No then keep it Red

                    if "Is the CR raised?" is yes and "Is the CR approved?" is yes then change it to Green

      if "Are there any changes between SOW Agreed Scope & Revised Scope?" is Yes and "Is the devaition between SOW Agreed scope and revised scope has major deviation?" is No --> Amber

                    if "Is the CR raised?" is yes or No then keep it Amber

                    if "Is the CR raised?" is yes and "Is the CR approved?" is No then keep it Amber

                    if "Is the CR raised?" is yes and "Is the CR approved?" is yes then change it to Green

      All the above questions are already available in the Sharepoint list source , based on the above logics I have to create a column for the accounts like below .

       

      I have tried this below DAX but not working as expected.

       

      Scope logic=
      IF (
          [ArethereanychangesbetweenSOWAgre] = "Yes" &&
              [IsthedevaitionbetweenSOWAgreedsc] = "Yes",
              "Red",
              IF (
                  [istheCRraised?] = "Yes" &&
                      [IstheCRapproved?] = "No",
                      "Red",
          IF (
          [ArethereanychangesbetweenSOWAgre] = "Yes" &&
              [IsthedevaitionbetweenSOWAgreedsc] = "No",
              "Amber",
          IF (
              [istheCRraised?] = "Yes" &&
                  [IstheCRapproved?] = "No",
                  "Amber",
                  "Green"
              )
          )))

      Can you please help to solve this DAX ?..

       

      Thanks

      DK

  • akito's avatar
    akito
    Frequent Visitor

    Thanks a lot Anonymous  - this worked very well.