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
sakhtar
Frequent Visitor

DAX Conversion for IF/AND Statement

Can someone please help me convert the following if statement in DAX. My conversion isnt producing the correct results, it may be because I dont know how to add the AND statment.

 

Also, how do you add an else make everything else statement at the end ; for example, below I put else "Out of Scope" which means if none of the above apply mark it as out of scope.

 

Thank you!

 

case 
when [Contract Action]="Closed" then "Contract Closed"
when [Contract Action]="Cancelled" then "Contract Closed"
when ([Contract Action]="Approved to Close") and ([Days to Contract Expiration]<-180) then "Past Due"
when ([Contract Action]="Approved to Close") and ([Days to Contract Expiration]<-90) then "Off Track"
when ([Contract Action]="Approved to Close") and ([Days to Contract Expiration]<0) then "On Track"
when ([Contract Action]="Approved to Close") and ([Days to Contract Expiration]>=0) then "Projected"
when ([Contract Action]="Approved to Extend") and ([Days to Contract Expiration]<0) then "Past Due"
when ([Contract Action]="Approved to Extend") and ([Days to Contract Expiration]<15) then "Off Track"
when ([Contract Action]="Approved to Extend") and ([Days to Contract Expiration]<45) then "On Track"
when ([Contract Action]="Approved to Extend") and ([Days to Contract Expiration]<=60) then "Projected"
when ([Contract Status]="Open") and ([Days to Contract Expiration]<0) then "Past Due"
when ([Contract Status]="Open") and ([Days to Contract Expiration]<16) then "Off Track"
when ([Contract Status]="Open") and ([Days to Contract Expiration]<46) then "On Track"
when ([Contract Status]="Open") and ([Days to Contract Expiration]<61) then "Projected"
when ([Contract Status]="Expired") and ([Days to Contract Expiration]<0) then "Past Due"
when ([Contract Status]="Expired") and ([Days to Contract Expiration]<16) then "Off Track"
when ([Contract Status]="Expired") and ([Days to Contract Expiration]<46) then "On Track"
when ([Contract Status]="Expired") and ([Days to Contract Expiration]<61) then "Projected"
when [Contract Status]="Letter Sent" then "On Track"

else "Out of Scope"
end

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @sakhtar ,

 

I'm assuming you are creating a new column so you should use the following sintax:

 

Column =
SWITCH (
    TRUE ();
    Table[Contract Action] = "Closed"; "Contract Closed";
    Table[Contract Action] = "Cancelled"; "Contract Closed";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] < -180 ); "Past Due";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] < -90 ); "Off Track";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] < 0 ); "On Track";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] >= 0 ); "Projected";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] < 0 ); "Past Due";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] < 15 ); "Off Track";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] < 45 ); "On Track";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] <= 60 ); "Projected";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 0 ); "Past Due";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 16 ); "Off Track";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 46 ); "On Track";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 61 ); "Projected";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 0 ); "Past Due";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 16 ); "Off Track";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 46 ); "On Track";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 61 ); "Projected";
    Table[Contract Status] = "Letter Sent"; "On Track";
    "Out of Scope"
)

If it's a measure it need to be redone in a different way, because measure need to have aggregators.

 

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @sakhtar ,

 

I'm assuming you are creating a new column so you should use the following sintax:

 

Column =
SWITCH (
    TRUE ();
    Table[Contract Action] = "Closed"; "Contract Closed";
    Table[Contract Action] = "Cancelled"; "Contract Closed";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] < -180 ); "Past Due";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] < -90 ); "Off Track";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] < 0 ); "On Track";
    ( Table[Contract Action] = "Approved to Close"
        && Table[Days to Contract Expiration] >= 0 ); "Projected";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] < 0 ); "Past Due";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] < 15 ); "Off Track";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] < 45 ); "On Track";
    ( Table[Contract Action] = "Approved to Extend"
        && Table[Days to Contract Expiration] <= 60 ); "Projected";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 0 ); "Past Due";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 16 ); "Off Track";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 46 ); "On Track";
    ( Table[Contract Status] = "Open"
        && Table[Days to Contract Expiration] < 61 ); "Projected";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 0 ); "Past Due";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 16 ); "Off Track";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 46 ); "On Track";
    ( Table[Contract Status] = "Expired"
        && Table[Days to Contract Expiration] < 61 ); "Projected";
    Table[Contract Status] = "Letter Sent"; "On Track";
    "Out of Scope"
)

If it's a measure it need to be redone in a different way, because measure need to have aggregators.

 

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.