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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Nested IFs and ANDs in DAX measure

Hi all,

 

Could someone please advise me on how I can translate this long nested IFs and ANDs formula from standard Excel (where it works perfectly) onto PBI DAX measure?:

 

=+IF(AND([@[Projekt-Nr.]]>9999;[@[Externe/Interne]]="Interne");"Interne - kein Zeitprojekt";

IF(AND([@[Projekt-Nr.]]>9999;[@[Externe/Interne]]="Externe");"Externe - kein Zeitprojekt";IF(ISNUMBER(SEARCH("reise";[@Aufgabe]));"Reisezeit";

IF(AND([@[Projekt-Name]]<>"";IF(ISNUMBER(SEARCH("supp";[@[Projekt-Name]]));"Support";"Not Support")="Not Support";[@[Pauschal/Aufwand]]="Pauschal";[@[Externe/Interne]]="Externe";[@[Eröffnung Budget]]-[@Verrechenbar]>=0);"Pauschal within budget";

IF(AND(IF(ISNUMBER(SEARCH("supp";[@[Projekt-Name]]));"Support";"Not Support")="Support");"Support";

IF(AND([@[Pauschal/Aufwand]]="Pauschal";[@[Externe/Interne]]="Externe";[@Budgetzeit]=0);"Pauschal set up with 0 budget";

IF(AND(IF(ISNUMBER(SEARCH("supp";[@[Projekt-Name]]));"Support";"Not Support")="Support");"Support";

IF(AND([@[Pauschal/Aufwand]]="Pauschal";[@[Externe/Interne]]="Externe";[@[Eröffnung Budget]]=0);"Pauschal started the period with 0 budget";

IF(AND(IF(ISNUMBER(SEARCH("supp";[@[Projekt-Name]]));"Support";"Not Support")="Support");"Support";

IF(AND([@[Pauschal/Aufwand]]="Pauschal";[@[Externe/Interne]]="Externe";[@[Eröffnung Budget]]<0);"Pauschal started the period with budget in minus";

IF(AND([@[Pauschal/Aufwand]]="Aufwand";[@[Externe/Interne]]="Externe";[@[Eröffnung Budget]]-[@Verrechenbar]>=0);"Aufwand within budget";

IF(AND([@[Pauschal/Aufwand]]="Aufwand";[@[Externe/Interne]]="Externe";[@[Eröffnung Budget]]-[@Verrechenbar]<0);"Aufwand overbudget";IF([@[Externe/Interne]]="Interne";"Interne";IF([@[Eröffnung Budget]]-[@Verrechenbar]<0;"Pauschal exceeded budget during period";

IF(AND([@[Eröffnung Budget]]=0;[@Verrechenbar]=0);"No Budget and Verrechenbar";"Strange Result")))))))))))))))

 

I tried (even utilising SWITCH), but couldn't get it to work.

 

Looking forward to your feedback.

 

Thanks.

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Dax is very close to excel formula,but remember to add "MAX" or "SELECTEDVALUE" before fields if you wanna create measures.

Such as :

Back Color = 
SWITCH(
    SELECTEDVALUE(DimCustomer[EnglishEducation]),
    "Bachelors","Green",
    "High School","Red",
    "Partial High School","Tan",
    "Graduate Degree","Yellow",
    "White"
)

Or 

Sales YTDOY :=
CALCULATE (
    SUMX (
        VALUES ( 'Date'[Calendar Year Month Number] ),
        VAR CurrentSales = [Sales Amount]
        VAR PreviousSales = [Sales LY]
        RETURN
            IF (
                AND (
                    CurrentSales <> 0,
                    PreviousSales <> 0
                ),
                CurrentSales - PreviousSales
            )
    ),
    DATESYTD ( 'Date'[Date] )
)

Check the reference below:

https://radacad.com/write-conditional-statement-using-switch-in-dax-and-power-bi

https://www.sqlbi.com/articles/optimizing-if-and-switch-expressions-using-variables/

 

Best Regards,
Kelly

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

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Dax is very close to excel formula,but remember to add "MAX" or "SELECTEDVALUE" before fields if you wanna create measures.

Such as :

Back Color = 
SWITCH(
    SELECTEDVALUE(DimCustomer[EnglishEducation]),
    "Bachelors","Green",
    "High School","Red",
    "Partial High School","Tan",
    "Graduate Degree","Yellow",
    "White"
)

Or 

Sales YTDOY :=
CALCULATE (
    SUMX (
        VALUES ( 'Date'[Calendar Year Month Number] ),
        VAR CurrentSales = [Sales Amount]
        VAR PreviousSales = [Sales LY]
        RETURN
            IF (
                AND (
                    CurrentSales <> 0,
                    PreviousSales <> 0
                ),
                CurrentSales - PreviousSales
            )
    ),
    DATESYTD ( 'Date'[Date] )
)

Check the reference below:

https://radacad.com/write-conditional-statement-using-switch-in-dax-and-power-bi

https://www.sqlbi.com/articles/optimizing-if-and-switch-expressions-using-variables/

 

Best Regards,
Kelly

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

Vera_33
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

Provide some sample data along with expected results in a format which people can copy to help understand the logic

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors