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! Request now

Reply
Anonymous
Not applicable

Nested If Statement

The DAX measure code below returns the engagement count and also term and year.  I only want the selected term to show for example "Fall", but I get both Fall and Spring as shown below.

 

pjb120_1-1680803522210.png

 

If I remove one If statement and run for either "Fall" or "Spring", I generate the correct ouput.

pjb120_2-1680803803640.png

 

pjb120_3-1680803878028.png

I am sure the issue is with the commas, but I am not sure how to make this an (If, Yes, No) statement.  


I greatly appreeciate your assistance with t his formatting issue.

-----------------------------------------------------------------------------------------------------------------------------

 

VAR _program = Enrollment[ProgramSelection]

VAR _termyear = Enrollment[TermYearSelection]
VAR _intdate = (Int(Right(Enrollment[AYYearSelection],4)))
VAR _sterm = LEFT(SELECTEDVALUE(Enrollment[Start Term and Year]),2)
 
VAR _enddate = SWITCH(_intdate,
                    2024, TODAY(),
                    2023, TODAY(),
                    2022,  EDATE(TODAY(), -12),
                    2021,  EDATE(TODAY(), -24),
                    2020,  EDATE(TODAY(), -36),
                    2019,  EDATE(TODAY(), -48)
                  )

VAR _count1 =   IF( _sterm = "Fa",                
                        CALCULATE(COUNTROWS(Enrollment),
                         Enrollment[Program] = _program,
                         Enrollment[Start Term and Year] = _termyear,
                         Enrollment[Deposit Intent to Enroll] = "Yes",
                         Enrollment[TermName] = SELECTEDVALUE(FallFilter[Term])),
                IF( _sterm = "Sp",                
                        CALCULATE(COUNTROWS(Enrollment),
                         Enrollment[Program] = _program,
                         Enrollment[Start Term and Year] = _termyear,
                         Enrollment[Deposit Intent to Enroll] = "Yes",
                         Enrollment[TermName] = SELECTEDVALUE(SpringFilter[Term])))        

)

RETURN
_count1
1 REPLY 1
Greg_Deckler
Community Champion
Community Champion

@Anonymous Try using SWITCH instead of nested IF statements.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.