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

View all the Fabric Data Days sessions on demand. View schedule

Reply
andytmcc
Helper I
Helper I

Add a Filter to a Switch

I have created a column that assigns a value (0, 0.5 or 1) based on the difference between 2 other columns:

 

locusofcontrol = SWITCH(

TRUE(),

'Loneliness All Data'[Locus Of Control Mean] > 'Loneliness All Data'[Locusofcontrol Previous Year],1,

'Loneliness All Data'[Locus Of Control Mean] = 'Loneliness All Data'[Locusofcontrol Previous Year],0.5,

0)
 
However, I only want these values to be created when the value "PC" is in the "Variable" column. How do I add the filter part into this DAX code?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

 

Try like this

JamesFr06_0-1663084385247.png

 

test_switch = switch(
True(),
and('Table'[Product]=1,'Table'[Serial Number]=99),1,
and('Table'[Product]=1,'Table'[Serial Number]<>99),2,0)

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi,

 

Try like this

JamesFr06_0-1663084385247.png

 

test_switch = switch(
True(),
and('Table'[Product]=1,'Table'[Serial Number]=99),1,
and('Table'[Product]=1,'Table'[Serial Number]<>99),2,0)
Greg_Deckler
Community Champion
Community Champion

@andytmcc Maybe:

locusofcontrol = SWITCH(

TRUE(),

MAX('Loneliness All Data'[PC]) = "Variable" && 'Loneliness All Data'[Locus Of Control Mean] > 'Loneliness All Data'[Locusofcontrol Previous Year],1,

MAX('Loneliness All Data'[PC]) = "Variable" && 'Loneliness All Data'[Locus Of Control Mean] = 'Loneliness All Data'[Locusofcontrol Previous Year],0.5,

0)


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.

Top Solution Authors
Top Kudoed Authors