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

Using SWITCH or IF functions to determine which SELECTEDVALUE statement to use

I have situation depending on slicer selection to execute the correct  SelectedValue function.  For some reason I am pulling all records, not just the records being requested.

The formats I have tried are as follows

 

SWITCH( _case,
               1, SelectedValue(slicervalue))

IF ( _case = 1, SelectedValue(slicervalue))

 

I have researched and attemted many optons with none of them working.

 

What is happening and how can I make this work.

 

I appreciate your help.

 

pjb120 

 

1 ACCEPTED SOLUTION
olgad
Super User
Super User

Is it a measure you are creating(you cannot create a column) ? With the measure switch usually goes with min/max

switch(max(index),

1, SelectedValue())


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime

View solution in original post

2 REPLIES 2
olgad
Super User
Super User

Is it a measure you are creating(you cannot create a column) ? With the measure switch usually goes with min/max

switch(max(index),

1, SelectedValue())


DID I ANSWER YOUR QUESTION? PLEASE MARK MY POST AS A SOLUTION! APPRECIATE YOUR KUDO/LIKE!
PROUD TO BE A SUPER USER!
Best Stories, Interesting Cases: PowerBI Storytime Newsletter
Linkedin Profile: Linkedin
YouTube Channel: PowerBI Storytime
Anonymous
Not applicable

Thanks for the quick reply.  I cannot use the MAX function as I am using the variable  _sterm.   I also tried with the If statement to no success.

 

Below is my measure, the objective is to substitute one of the following Fall, Spring, or Summer into the variable _iterm , it should only return the records for one off these terms.   If I make _iterm = SELECTEDVALUE(FallFilter[Term]) only he Fall records are returned.

 

Any advice you can offer is appreciated.,

 

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

 

EnrollmentCountX =

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 _iterm = If (_sterm = "Fa",  SELECTEDVALUE(FallFilter[Term]))
                   
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 _count =    CALCULATE(COUNTROWS(Enrollment),
                All(Enrollment[Deposit Intent to Enroll Date/Time]),
                Enrollment[Program] = _program,
                Enrollment[Start Term and Year] = _termyear,
                Enrollment[Deposit Intent to Enroll] = "Yes",
                Enrollment[Deposit Intent to Enroll Date/Time] <= _enddate,
                FILTER('Enrollment',CONTAINSSTRING('Enrollment'[Start Term and Year], _iterm)))
RETURN
_count

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