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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
justinh
Advocate IV
Advocate IV

Using SWITCH within KEEPFILTERS and IN?

Is it possible to switch out the list inside of a KEEPFILTERS IN argument?
I can't seem to get it to work. 

I want my end user to be able to make a parameter selection, and that selection changes the list that the KEEPFILTERS statement looks at after the IN. 

justinh_0-1709929770319.png

 

1 ACCEPTED SOLUTION

This version even keeps the "KeepFilters" in place:

 

VAR _UserSelection= [Selected Conversion Type]
VAR _Table = 
	CALCULATETABLE(
		SUMMARIZE(
			b_Assortment_Bridge,
			b_Assortment_Bridge[Inventory_Key],
			b_Assortment_Bridge[Assortment StdCost Ratio],
			b_Assortment_Bridge[Assortment Flag]
		),
		KEEPFILTERS( 
			SWITCH(
				_UserSelection,
				"Both",
					b_Assortment_Bridge[Assortment Flag] IN {"", "A", "B"},
				"A Only",
					b_Assortment_Bridge[Assortment Flag] IN {"", "A"},
				"B Only",
					b_Assortment_Bridge[Assortment Flag] IN {"", "B"},
				"Off",
					b_Assortment_Bridge[Assortment Flag] IN {""}
			)
		)
	)
VAR _Measure = 
	SUMX(
		_Table,
		CALCULATE( [.Sales - Selling SKUs] ) * [Assortment StdCost Ratio]
	)

RETURN
	_Measure

 

View solution in original post

4 REPLIES 4
ThxAlot
Super User
Super User

Not surprising _SwitchList doesn't work because it returns a string whereas IN operator requires a table value; btw, IN is the syntax sugar for CONTAINSROW() function.

 

Can't get any useful info on data model itself; the only advice I can offer is to use a slicer like this,

 ... IN Values(OPT[Type])

ThxAlot_0-1710092445317.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Thank you for your reply. I like your solution, except I want a default setting if they choose nothing. I've gotten it to work my way, but modified from my original attempt. 
Btw, I thought _SwitchList would be returning a list/single column table, not a string. Clearly I was wrong. 
Thank you again. 

justinh
Advocate IV
Advocate IV

This was the cleanest I could make the code and have it still work as expected.

justinh_0-1709934566952.png

 

This version even keeps the "KeepFilters" in place:

 

VAR _UserSelection= [Selected Conversion Type]
VAR _Table = 
	CALCULATETABLE(
		SUMMARIZE(
			b_Assortment_Bridge,
			b_Assortment_Bridge[Inventory_Key],
			b_Assortment_Bridge[Assortment StdCost Ratio],
			b_Assortment_Bridge[Assortment Flag]
		),
		KEEPFILTERS( 
			SWITCH(
				_UserSelection,
				"Both",
					b_Assortment_Bridge[Assortment Flag] IN {"", "A", "B"},
				"A Only",
					b_Assortment_Bridge[Assortment Flag] IN {"", "A"},
				"B Only",
					b_Assortment_Bridge[Assortment Flag] IN {"", "B"},
				"Off",
					b_Assortment_Bridge[Assortment Flag] IN {""}
			)
		)
	)
VAR _Measure = 
	SUMX(
		_Table,
		CALCULATE( [.Sales - Selling SKUs] ) * [Assortment StdCost Ratio]
	)

RETURN
	_Measure

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.